Relates :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : java version "1.5.0_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05) Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Linux jks-desktop 2.6.12-1.1376_FC3 #1 Fri Aug 26 23:27:26 EDT 2005 i686 athlon i386 GNU/Linux A DESCRIPTION OF THE PROBLEM : If a Thread.start() throws an OutOfMemoryError because a native system thread couldn't be created, trying to call start() again results in a IllegalThreadStateException, even though the the thread never started. I was not able to reduce the problem in jdk 1.4.2, so this seems to be a regressions. REPRODUCIBILITY : This bug can be reproduced often. ---------- BEGIN SOURCE ---------- public class ThreadSpinner { /** Tries to start a thread until successfull. */ private static void start_thread(final Thread orig_t){ Thread t = orig_t; boolean sent_off = false; int times_tried = 0; while (true) try{ times_tried++; t.start(); sent_off = true; break; } catch(IllegalThreadStateException e){ e.printStackTrace(); System.exit(1); }catch(OutOfMemoryError e){ if (times_tried > 1) System.err.println("already tried "+times_tried+" times"); t = new Thread(orig_t.getThreadGroup(), orig_t, orig_t.getName()); try{ Thread.sleep(3000); } catch(InterruptedException e2){} } } public static void main(String[] args){ ThreadGroup tg = new ThreadGroup("spun"); final Object waiter = new Object(); final long hour = 60 * 60 * 1000; int i = 0; while(true){ i++; Runnable r = new Runnable(){ public void run(){ //try{ Thread.sleep(hour); } catch(Exception e){}; try{ waiter.wait(hour); } catch(Exception e){}; }}; Thread t = new Thread(tg, r,"thread "+i,1000000); start_thread(t); } } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Use a Runnable, so a new Thread can be created each time through the loop.
|