我正在编写一个包含5个线程的应用程序,它们可以同时从Web获取一些信息,并在缓冲类中填充5个不同的字段.
当所有线程完成工作时,我需要验证缓冲区数据并将其存储在数据库中.
我该怎么做(当所有线程完成工作时收到警报)?
我创建了一个Java实用程序,在x内部的x花式zip文件(twx)中搜索XML.
最初这是一个命令行实用程序,没有线程.
当我将其移动到使用JavaFX时,我遇到了冻结问题,然后将所有搜索移动到Task对象中进行修复.
我需要一些方法来跟踪进度,所以我实现了Progress属性和ProgressBar来跟踪.
它工作得很好,但由于我已经是多线程,为什么不为每个Zip搜索创建一个线程.不幸的是,这种方法效果不佳.
为了跟踪我创建一个任务数组,然后创建一个处理它们的主任务.我使用处理所有更新的进度和总属性.
这是代码
public class TextSearch {
final private SimpleDoubleProperty progress = new SimpleDoubleProperty();
final private SimpleDoubleProperty total = new SimpleDoubleProperty();
/**
*
* Kicks off a search. Creates a Task/Thread for each twx search.
* @return A task object that maintains all of the twx searches.
*
* @throws ZipException If the zip file is unreadable.
* @throws IOException If the file is unreadable.
* @throws JDOMException If the xml in the files are unreadable. …Run Code Online (Sandbox Code Playgroud)