implement Thread.[get|set]ContextClassloader()

This commit is contained in:
Joel Dice 2007-07-31 18:08:20 -06:00
parent 38d4ee6e07
commit b56eed68be
3 changed files with 18 additions and 3 deletions

View File

@ -9,11 +9,14 @@ public class Thread implements Runnable {
private Map<ThreadLocal, Object> locals;
private boolean interrupted;
private Object sleepLock;
private ClassLoader classLoader;
public Thread(Runnable task) {
this.task = task;
Map<ThreadLocal, Object> map = currentThread().locals;
Thread current = currentThread();
Map<ThreadLocal, Object> map = current.locals;
if (map != null) {
for (Map.Entry<ThreadLocal, Object> e: map.entrySet()) {
if (e.getKey() instanceof InheritableThreadLocal) {
@ -22,6 +25,8 @@ public class Thread implements Runnable {
}
}
}
classLoader = current.classLoader;
}
public synchronized void start() {
@ -43,6 +48,14 @@ public class Thread implements Runnable {
}
}
public ClassLoader getContextClassLoader() {
return classLoader;
}
public void setContextClassLoader(ClassLoader v) {
classLoader = v;
}
public Map<ThreadLocal, Object> locals() {
if (locals == null) {
locals = new WeakHashMap();

View File

@ -1336,7 +1336,8 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
populateBuiltinMap(t, m->builtinMap);
t->javaThread = makeThread(t, reinterpret_cast<int64_t>(t), 0, 0, 0, 0);
t->javaThread = makeThread
(t, reinterpret_cast<int64_t>(t), 0, 0, 0, 0, t->vm->loader);
} else {
threadPeer(this, javaThread) = reinterpret_cast<jlong>(this);
parent->child = this;

View File

@ -140,7 +140,8 @@
(object task)
(object locals)
(uint8_t interrupted)
(object sleepLock))
(object sleepLock)
(object classLoader))
(type stackTraceElement java/lang/StackTraceElement
(extends jobject)