What | Where |
---|---|
Introduction | vogella |
Whereever possible use the safe Structures from | concurrent package |
Das Concurrent Package bietet viele fertige Multithreading Klassen.
A framework to execute parallel task. The mechanism is described here.
//A nice way to stop the UI thread, in order to wait for a job, without blocking the UI Jobs coming from other Threads while(job.getResult()==null) { Display.getDefault().readAndDispatch(); }
On every thread there should be an own Exception-handling. Putting a new Thread creation into try-catch block won't catch the Exceptions.
//ATTENTION: the exception is not catched! try{ Runnable r = new Runnable() { @Override public void run() { System.out.println("Thread"); Display.getDefault().syncExec(new Runnable() { @Override public void run() { System.out.println("ThreadGUI"); throw new NullPointerException(); } }); } }; Thread t = new Thread(r); t.start(); }catch(NullPointerException e){ //nothing } System.out.println("Ende");