首先写一个工具,
public class CustomThreadService
{
private static CustomThreadService instance = new CustomThreadService();
private ThreadPoolExecutor service = null;
private CustomThreadService()
{
BlockingQueue<Runnable> workQueue =
new LinkedBlockingQueue<Runnable>(3000);
this.service =
new ThreadPoolExecutor(10, 30, 30L, TimeUnit.SECONDS, workQueue,
new ThreadPoolExecutor.CallerRunsPolicy());
}
public static synchronized CustomThreadService getInstance()
{
return instance;
}
public void execute(Runnable command)
{
this.service.execute(command);
}
}
调用这个工具类,
CustomThreadService.getInstance().execute(new Runnable()
{
public void run()
{
try
{
if (logger.isDebugEnabled())
{
logger.debug("Enter syncMethod,msisdn is empty!!");
}
//此处编写自己的demo
}
catch (Throwable e)
{
logger.error("unbindaccount or send mq execption:",
e);
}
}
});