Java Doc for ReusableThread.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » JGroups 2.4.1 sp3 » org.jgroups.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.jgroups.util.ReusableThread

ReusableThread
public class ReusableThread implements Runnable(Code)
Reusable thread class. Instead of creating a new thread per task, this instance can be reused to run different tasks in turn. This is done by looping and assigning the Runnable task objects whose run method is then called.
Tasks are Runnable objects and should be prepared to terminate when they receive an InterruptedException. This is thrown by the stop() method.

The following situations have to be tested:

  1. ReusableThread is started. Then, brefore assigning a task, it is stopped again
  2. ReusableThread is started, assigned a long running task. Then, before task is done, stop() is called
  3. ReusableThread is started, assigned a task. Then waitUntilDone() is called, then stop()
  4. ReusableThread is started, assigned a number of tasks (waitUntilDone() called between tasks), then stopped
  5. ReusableThread is started, assigned a task

author:
   Bela Ban


Field Summary
final static  longTASK_JOIN_TIME
    
final protected static  Loglog
    
volatile  booleansuspended
    
 Runnabletask
    
volatile  Threadthread
    
 Stringthread_name
    

Constructor Summary
public  ReusableThread()
    
public  ReusableThread(String thread_name)
    

Method Summary
public  booleanassignTask(Runnable t)
     Assigns a task to the thread.
public  voidassignThreadLocalListener(ThreadLocalListener tl_listener)
     Assigns a ThreadLocalListener to the current ReusableThread.
public  booleanavailable()
    
public  booleandone()
    
public  booleanisAlive()
    
 StringprintObj(Object obj)
    
public  voidresume()
     Resumes the thread.
public  voidrun()
     Delicate piece of code (means very important :-)).
public  voidstart()
    
public  voidstop()
     Stops the thread by setting thread=null and interrupting it.
public  voidsuspend()
     Suspends the thread.
public  StringtoString()
    
public  voidwaitUntilDone()
    

Field Detail
TASK_JOIN_TIME
final static long TASK_JOIN_TIME(Code)



log
final protected static Log log(Code)



suspended
volatile boolean suspended(Code)



task
Runnable task(Code)



thread
volatile Thread thread(Code)



thread_name
String thread_name(Code)




Constructor Detail
ReusableThread
public ReusableThread()(Code)



ReusableThread
public ReusableThread(String thread_name)(Code)




Method Detail
assignTask
public boolean assignTask(Runnable t)(Code)
Assigns a task to the thread. If the thread is not running, it will be started. It it is already working on a task, it will reject the new task. Returns true if task could be assigned auccessfully



assignThreadLocalListener
public void assignThreadLocalListener(ThreadLocalListener tl_listener)(Code)
Assigns a ThreadLocalListener to the current ReusableThread. The ThreadLocalListener sets ThreadLocal's values for the lifetime of the task for the thread that is used to run the task. The ThreadLocalListener will reset values upon the task returning and at this point will be deleted.



available
public boolean available()(Code)



done
public boolean done()(Code)



isAlive
public boolean isAlive()(Code)



printObj
String printObj(Object obj)(Code)



resume
public void resume()(Code)
Resumes the thread. Noop if not suspended



run
public void run()(Code)
Delicate piece of code (means very important :-)). Works as follows: loops until stop is true. Waits in a loop until task is assigned. Then runs the task and notifies waiters that it's done when task is completed. Then returns to the first loop to wait for more work. Does so until stop() is called, which sets stop=true and interrupts the thread. If waiting for a task, the thread terminates. If running a task, the task is interrupted, and the thread terminates. If the task is not interrupible, the stop() method will wait for 3 secs (join on the thread), then return. This means that the run() method of the task will complete and only then will the thread be garbage-collected.



start
public void start()(Code)
Will always be called from synchronized method, no need to do our own synchronization



stop
public void stop()(Code)
Stops the thread by setting thread=null and interrupting it. The run() method catches the InterruptedException and checks whether thread==null. If this is the case, it will terminate



suspend
public void suspend()(Code)
Suspends the thread. Does nothing if already suspended. If a thread is waiting to be assigned a task, or is currently running a (possibly long-running) task, then it will be suspended the next time it waits for suspended==false (second wait-loop in run())



toString
public String toString()(Code)



waitUntilDone
public void waitUntilDone()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.