2009-04-07 sponge
* SimpleTimer2, SimpleScheduler fixed so that the threads all run from The main threadgroup, not in the current possible child threadgroup. So long as any SimpleTimer2/SimpleScheduler is started *BEFORE* any child threadgroups, the constructors are threadgroup safe. What would be super cool is if they were to be all jailed within thier very own threadgroup too, but, I2P isn't up to the task of this yet. * Fixes to BOB to ensure the above is true.
This commit is contained in:
@ -42,6 +42,7 @@ public class SimpleScheduler {
|
||||
_name = name;
|
||||
_count = 0;
|
||||
_executor = new ScheduledThreadPoolExecutor(THREADS, new CustomThreadFactory());
|
||||
_executor.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,10 +91,11 @@ public class SimpleScheduler {
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread rv = Executors.defaultThreadFactory().newThread(r);
|
||||
rv.setName(_name + ' ' + (++_count) + '/' + THREADS);
|
||||
String name = rv.getThreadGroup().getName();
|
||||
if(!(name.isEmpty() || name.equals("Main") || name.equals("main"))) {
|
||||
(new Exception("OWCH! DAMN! Wrong ThreadGroup `" + name +"', `" + rv.getName() + "'")).printStackTrace();
|
||||
}
|
||||
// Uncomment this to test threadgrouping, but we should be all safe now that the constructor preallocates!
|
||||
// String name = rv.getThreadGroup().getName();
|
||||
// if(!name.equals("main")) {
|
||||
// (new Exception("OWCH! DAMN! Wrong ThreadGroup `" + name +"', `" + rv.getName() + "'")).printStackTrace();
|
||||
// }
|
||||
rv.setDaemon(true);
|
||||
return rv;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class SimpleTimer2 {
|
||||
_name = name;
|
||||
_count = 0;
|
||||
_executor = new CustomScheduledThreadPoolExecutor(THREADS, new CustomThreadFactory());
|
||||
_executor.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,10 +68,11 @@ public class SimpleTimer2 {
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread rv = Executors.defaultThreadFactory().newThread(r);
|
||||
rv.setName(_name + ' ' + (++_count) + '/' + THREADS);
|
||||
String name = rv.getThreadGroup().getName();
|
||||
if(!(name.isEmpty() || name.equals("Main") || name.equals("main"))) {
|
||||
(new Exception("OWCH! DAMN! Wrong ThreadGroup `" + name +"', `" + rv.getName() + "'")).printStackTrace();
|
||||
}
|
||||
// Uncomment this to test threadgrouping, but we should be all safe now that the constructor preallocates!
|
||||
// String name = rv.getThreadGroup().getName();
|
||||
// if(!name.equals("main")) {
|
||||
// (new Exception("OWCH! DAMN! Wrong ThreadGroup `" + name +"', `" + rv.getName() + "'")).printStackTrace();
|
||||
// }
|
||||
rv.setDaemon(true);
|
||||
return rv;
|
||||
}
|
||||
|
Reference in New Issue
Block a user