Re: start a thread in jini
Gregg Wonderly <[email protected]> Mon, 12 May 2008 09:23:14 -0500
| Newsgroups | gmane.comp.java.sun.jini |
|---|---|
| Message-ID | <[email protected]> |
liang li wrote: > i wana start a thread which does something periodly in jini. > there are to many way to start a thread, however, which is the > right way. A simple thing to consider is whether there are several such things that you will do, or just the one. For 3 or more things, I'd suggest a ThreadPoolExecutor. If the tasks are done with time based triggering, a ScheduledThreadPoolExecutor is convenient. If the events are triggered by some event, such as service discovery, or lease/transaction expiration based etc, then use a ThreadPoolExecutor to dispatch them as needed. If you just have one or two things to do, the thread pool won't add much value., it will just be another live object to deal with the lifecycle thereof. But I usually use a Runnable/Callable based design from the start to allow an easy switch over. Future's are particularly nice for things that need to be done in the background, but which multiple threads of execution need the results of. The work can be dispatched in a synchronized block, and then everyone can block on Future.get(). Gregg Wonderly -------------------------------------------------------------------------- Getting Started: http://www.jini.org/wiki/Category:Getting_Started Community Web Site: http://jini.org jini-users Archive: http://archives.java.sun.com/archives/jini-users.html Unsubscribing: email "signoff JINI-USERS" to [email protected]