Java Doc for RequestProcessor.java in  » IDE-Netbeans » openide » org » openide » 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 » IDE Netbeans » openide » org.openide.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.openide.util.RequestProcessor

RequestProcessor
final public class RequestProcessor (Code)
Request processor that is capable to execute requests in dedicated threads. You can create your own instance or use the shared one.

There are several use cases for RequestProcessor:

  • Having something done asynchronously in some other thread, not insisting on any kind of serialization of the requests: Use RequestProcessor. RequestProcessor.getDefault . RequestProcessor.post(java.lang.Runnable) post(runnable) for this purpose.
  • Having something done later in some other thread: Use RequestProcessor. RequestProcessor.getDefault . RequestProcessor.post(java.lang.Runnable,int) post(runnable, delay)
  • Having something done periodically in any thread: Use the RequestProcessor.Task 's ability to RequestProcessor.Task.schedule schedule() , like
     static RequestProcessor.Task CLEANER = RequestProcessor.getDefault().post(runnable,DELAY);
     public void run() {
     doTheWork();
     CLEANER.schedule(DELAY);
     }
     
    Note: Please think twice before implementing some periodic background activity. It is generally considered evil if it will run regardless of user actions and the application state, even while the application is minimized / not currently used.
  • Having something done in some other thread but properly ordered: Create a private instance of the RequestProcessor.RequestProcessor(java.lang.String) RequestProcessor(name) and use it from all places you'd like to have serialized. It works like a simple Mutex.
  • Having some entity that will do processing in a limited number of threads paralelly: Create a private instance of the RequestProcessor.RequestProcessor(java.lang.Stringint) RequestProcessor(name,throughput) set proper throughput and use it to schedule the work. It works like a queue of requests passing through a semafore with predefined number of DOWN()s.
Note: If you don't need to serialize your requests but you're generating them in bursts, you should use your private RequestProcessor instance with limited throughput (probably set to 1), NetBeans would try to run all your requests in parallel otherwise.

Since version 6.3 there is a conditional support for interruption of long running tasks. There always was a way how to cancel not yet running task using RequestProcessor.Task.cancel but if the task was already running, one was out of luck. Since version 6.3 the thread running the task is interrupted and the Runnable can check for that and terminate its execution sooner. In the runnable one shall check for thread interruption (done from RequestProcessor.Task.cancel ) and if true, return immediatelly as in this example:

 public void run () {
 while (veryLongTimeLook) {
 doAPieceOfIt ();
 if (Thread.interrupted ()) return;
 }
 }
 

author:
   Petr Nejedly, Jaroslav Tulach

Inner Class :final public class Task extends org.openide.util.Task implements Cancellable

Field Summary
final static  booleanSLOW
    
 Stringname
    
 booleanstopped
    

Constructor Summary
public  RequestProcessor()
     Creates new RequestProcessor with automatically assigned unique name.
public  RequestProcessor(String name)
     Creates a new named RequestProcessor with throughput 1.
public  RequestProcessor(String name, int throughput)
     Creates a new named RequestProcessor with defined throughput.
public  RequestProcessor(String name, int throughput, boolean interruptThread)
     Creates a new named RequestProcessor with defined throughput which can support interruption of the thread the processor runs in. There always was a way how to cancel not yet running task using RequestProcessor.Task.cancel but if the task was already running, one was out of luck.

Method Summary
 TaskaskForWork(Processor worker, String debug)
    
public  Taskcreate(Runnable run)
     Creates request that can be later started by setting its delay. The request is not immediatelly put into the queue.
public  Taskcreate(Runnable run, boolean initiallyFinished)
     Creates request that can be later started by setting its delay. The request is not immediatelly put into the queue.
public static  TaskcreateRequest(Runnable run)
     Creates request that can be later started by setting its delay. The request is not immediatelly put into the queue.
 voidenqueue(Item item)
     Place the Task to the queue of pending tasks for immediate processing.
public static  RequestProcessorgetDefault()
     The getter for the shared instance of the RequestProcessor. This instance is shared by anybody who needs a way of performing sporadic or repeated asynchronous work. Tasks posted to this instance may be canceled until they start their execution.
public  booleanisRequestProcessorThread()
     Tests if the current thread is request processor thread. This method could be used to prevent the deadlocks using waitFinished method.
static  Loggerlogger()
     Logger for the error manager.
public  Taskpost(Runnable run)
     This methods asks the request processor to start given runnable immediately.
public  Taskpost(Runnable run, int timeToWait)
     This methods asks the request processor to start given runnable after timeToWait milliseconds.
public  Taskpost(Runnable run, int timeToWait, int priority)
     This methods asks the request processor to start given runnable after timeToWait milliseconds.
public static  TaskpostRequest(Runnable run)
     This methods asks the request processor to start given runnable after timeToWait milliseconds.
public static  TaskpostRequest(Runnable run, int timeToWait)
     This methods asks the request processor to start given runnable after timeToWait milliseconds.
public static  TaskpostRequest(Runnable run, int timeToWait, int priority)
     This methods asks the request processor to start given runnable after timeToWait milliseconds.
public  voidstop()
     Stops processing of runnables processor.

Field Detail
SLOW
final static boolean SLOW(Code)



name
String name(Code)
The name of the RequestProcessor instance



stopped
boolean stopped(Code)
If the RP was stopped, this variable will be set, every new post() will throw an exception and no task will be processed any further




Constructor Detail
RequestProcessor
public RequestProcessor()(Code)
Creates new RequestProcessor with automatically assigned unique name.



RequestProcessor
public RequestProcessor(String name)(Code)
Creates a new named RequestProcessor with throughput 1.
Parameters:
  name - the name to use for the request processor thread



RequestProcessor
public RequestProcessor(String name, int throughput)(Code)
Creates a new named RequestProcessor with defined throughput.
Parameters:
  name - the name to use for the request processor thread
Parameters:
  throughput - the maximal count of requests allowed to run in parallel
since:
   OpenAPI version 2.12



RequestProcessor
public RequestProcessor(String name, int throughput, boolean interruptThread)(Code)
Creates a new named RequestProcessor with defined throughput which can support interruption of the thread the processor runs in. There always was a way how to cancel not yet running task using RequestProcessor.Task.cancel but if the task was already running, one was out of luck. With this constructor one can create a RequestProcessor which threads thread running tasks are interrupted and the Runnable can check for that and terminate its execution sooner. In the runnable one shall check for thread interruption (done from RequestProcessor.Task.cancel ) and if true, return immediatelly as in this example:
 public void run () {
 while (veryLongTimeLook) {
 doAPieceOfIt ();
 if (Thread.interrupted ()) return;
 }
 }
 

Parameters:
  name - the name to use for the request processor thread
Parameters:
  throughput - the maximal count of requests allowed to run in parallel
Parameters:
  interruptThread - true if RequestProcessor.Task.cancel shall interrupt the thread
since:
   6.3




Method Detail
askForWork
Task askForWork(Processor worker, String debug)(Code)



create
public Task create(Runnable run)(Code)
Creates request that can be later started by setting its delay. The request is not immediatelly put into the queue. It is planned after setting its delay by schedule method. By default the initial state of the task is !isFinished() so doing waitFinished() will block on and wait until the task is scheduled.
Parameters:
  run - action to run in the process the task to control execution of given action



create
public Task create(Runnable run, boolean initiallyFinished)(Code)
Creates request that can be later started by setting its delay. The request is not immediatelly put into the queue. It is planned after setting its delay by schedule method.
Parameters:
  run - action to run in the process
Parameters:
  initiallyFinished - should the task be marked initially finished? If so the Task.waitFinished on the task will succeeded immediatelly eventhe task has not yet been Task.scheduled. the task to control execution of given action
since:
   6.8



createRequest
public static Task createRequest(Runnable run)(Code)
Creates request that can be later started by setting its delay. The request is not immediatelly put into the queue. It is planned after setting its delay by setDelay method.
Parameters:
  run - action to run in the process the task to control execution of given action



enqueue
void enqueue(Item item)(Code)
Place the Task to the queue of pending tasks for immediate processing. If there is no other Task planned, this task is immediatelly processed in the Processor.



getDefault
public static RequestProcessor getDefault()(Code)
The getter for the shared instance of the RequestProcessor. This instance is shared by anybody who needs a way of performing sporadic or repeated asynchronous work. Tasks posted to this instance may be canceled until they start their execution. If a there is a need to cancel a task while it is running a seperate request processor needs to be created via RequestProcessor.RequestProcessor(String,int,boolean) constructor. an instance of RequestProcessor that is capable of performing"unlimited" (currently limited to 50, just for case of misuse) numberof requests in parallel.
See Also:   RequestProcessor.RequestProcessor(String,int,boolean)
See Also:   RequestProcessor.Task.cancel
since:
   version 2.12



isRequestProcessorThread
public boolean isRequestProcessorThread()(Code)
Tests if the current thread is request processor thread. This method could be used to prevent the deadlocks using waitFinished method. Any two tasks created by request processor must not wait for themself. true if the current thread is request processorthread, otherwise false



logger
static Logger logger()(Code)
Logger for the error manager.



post
public Task post(Runnable run)(Code)
This methods asks the request processor to start given runnable immediately. The default priority is Thread.MIN_PRIORITY .
Parameters:
  run - class to run the task to control the request



post
public Task post(Runnable run, int timeToWait)(Code)
This methods asks the request processor to start given runnable after timeToWait milliseconds. The default priority is Thread.MIN_PRIORITY .
Parameters:
  run - class to run
Parameters:
  timeToWait - to wait before execution the task to control the request



post
public Task post(Runnable run, int timeToWait, int priority)(Code)
This methods asks the request processor to start given runnable after timeToWait milliseconds. Given priority is assigned to the request.

For request relaying please consider:

 post(run, timeToWait, Thread.currentThread().getPriority());
 

Parameters:
  run - class to run
Parameters:
  timeToWait - to wait before execution
Parameters:
  priority - the priority from Thread.MIN_PRIORITY to Thread.MAX_PRIORITY the task to control the request



postRequest
public static Task postRequest(Runnable run)(Code)
This methods asks the request processor to start given runnable after timeToWait milliseconds. The default priority is Thread.MIN_PRIORITY .
Parameters:
  run - class to run the task to control the request



postRequest
public static Task postRequest(Runnable run, int timeToWait)(Code)
This methods asks the request processor to start given runnable after timeToWait milliseconds. The default priority is Thread.MIN_PRIORITY .
Parameters:
  run - class to run
Parameters:
  timeToWait - to wait before execution the task to control the request



postRequest
public static Task postRequest(Runnable run, int timeToWait, int priority)(Code)
This methods asks the request processor to start given runnable after timeToWait milliseconds. Given priority is assigned to the request.
Parameters:
  run - class to run
Parameters:
  timeToWait - to wait before execution
Parameters:
  priority - the priority from Thread.MIN_PRIORITY to Thread.MAX_PRIORITY the task to control the request



stop
public void stop()(Code)
Stops processing of runnables processor. The currently running runnable is finished and no new is started.



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.