如何判断ThreadPool的每个Thread是否在等待

时间:2015-12-13 23:16:34

标签: java multithreading thread-safety threadpool blockingqueue

我有一个包含很多线程的ThreadPool。 如果此线程池的每个线程都在BlockingQueue上等待,则任务完成。我怎么能弄清楚每个线程是否在等待所以我可以关闭线程池?

1 个答案:

答案 0 :(得分:0)

您应该使用较长的超时值调用options然后调用var formData = new FormData(); formData.append('file', $('#fileUpload')[0].files[0]); options = JSON.stringify(options); formData.append('options', options); //append it with the form data and take it apart on the server $.ajax({ url: "url", type: "POST", data: formData, processData: false, contentType: false, success: function (data) { }, error: function (msg) { showMsg("error", msg.statusText + ". Press F12 for details"); console.log(msg); } }); 。任务完成后,它将关闭。

请参阅此答案:How to wait for all threads to finish, using ExecutorService?