Skip to content

Instantly share code, notes, and snippets.

@clebertsuconic
Created August 4, 2014 13:02
Show Gist options
  • Save clebertsuconic/c192aefd7de11009e945 to your computer and use it in GitHub Desktop.
Save clebertsuconic/c192aefd7de11009e945 to your computer and use it in GitHub Desktop.
public Thread newThread(final Runnable command)
{
// attach the thread to a group only if there is no security manager:
// when sandboxed, the code does not have the RuntimePermission modifyThreadGroup
final Thread t = (Thread)AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
Thread t;
if (System.getSecurityManager() == null)
{
t = new Thread(group, command, "Thread-" + threadCount.getAndIncrement() + " (" + group.getName() + ")");
}
else
{
t = new Thread(command, "Thread-" + threadCount.getAndIncrement());
}
return t;
}
});
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
t.setDaemon(daemon);
t.setPriority(threadPriority);
return null;
}
});
try
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
t.setContextClassLoader(tccl);
return null;
}
});
}
catch (java.security.AccessControlException e)
{
HornetQUtilLogger.LOGGER.missingPrivsForClassloader();
}
return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment