programming:java:multithreading
This is an old revision of the document!
−Table of Contents
Multithreading
What | Where |
---|---|
Introduction | vogella |
Whereever possible use the safe Structures from | concurrent package |
PitFalls
- Do not use TimeStamps to synchronize Threads. Therere can be more than 1 action every millisecond - what to do with equal TimeStamps?
Concurrent Package
Das Concurrent Package bietet viele fertige Multithreading Klassen.
ForkJoin
A framework to execute parallel task. The mechanism is described here.
1 2 3 4 |
//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(); } |
Try-Catch is Bypassed in nested threads
On every thread there should be an own Exception-handling. Putting a new Thread creation into try-catch block won't catch the Exceptions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//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" ); |
programming/java/multithreading.1497448749.txt.gz · Last modified: (external edit)