我想知道哪种方法是在Java中实现某种后台任务的最有效方法(我想那是某种非阻塞线程).更准确地说-我有一些Java代码,然后在某个时候我需要执行长时间运行的操作.我想做的是在后台执行该操作,以便程序的其余部分可以继续执行,并且当该任务完成时,只需更新一些特定的对象即可.然后,其他组件将检测到此更改.
I was wondering which would be the most efficient approach to implement some kind of background task in java (I guess that would be some kind of nonblocking Threads). To be more precise - I have some java code and then at some point I need to execute a long running operation. What I would like to do is to execute that operation in the background so that the rest of the program can continue executing and when that task is completed just update some specific object which. This change would be then detected by other components.
推荐答案您应该使用线程池,
java.sun/docs /books/tutorial/essential/concurrency/pools.html
更多推荐
Java后台任务
发布评论