I’ve looked through the books/docs about NBP, but there is nothing directly talks about multithreaded programming in NBP. Is there anything particular that needs attention regarding to multithreading in NBP? So, if I want to create a multithreaded NBP application, I just need to follow regular Java multithreaded programming practices, right?
I’ve looked through the books/docs about NBP, but there is nothing directly talks about
Share
The main thing to look at would be RequestProcessor and RequestProcessor.Task. RequestProcessor is a thread pool; a RequestProcessor.Task is a job.
Most of what RequestProcessor does is similar to what ExecutorService now does in the JDK. The main thing that is not easy w/ just the JDK is creating a task which can be rescheduled and run repeatedly. That is very useful if you, say, want to perform some work after a timeout when the user stops typing:
If you’re using the Nodes API, it is thread-safe, and you can update your nodes as you wish.
If you are doing something which touches Swing components, remember to always run that code with EventQueue.invokeLater(Runnable) – and never use EventQueue.invokeAndWait() – it is a recipe for deadlocks.
If you have code which may sometimes be called on the event thread and sometimes not, NetBeans has a simple way to ensure your code runs on the event thread: Mutex.EVENT.readAccess (new Mutex.Action() { … })