我的程序是这样的ThreadPool threadPool = new ThreadPoolExecutor(2, 30, 1,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1),
new ThreadPoolExecutor.CallerRunsPolicy()); //建立线程池for(int i=0;i<2000;i++){threadPool.submit(一个线程);
threadPool.submit(一个线程);
threadPool.submit(一个线程);
threadPool.submit(一个线程);}
try{
boolean loop = true;
do{
out.print("still checking......");
loop = !threadPool.awaitTermination(5, TimeUnit.SECONDS);
} while(loop);
}catch(Exception e){
}先寻立线程池,然后再提交很多线程,再用awaitTermination 检查全部线程运行完了没有,但现在有一个问题,我在自己的机子上运行,其中有三个线程一直不能结束,要等很久才能结束,也就是说,输出了很多次
still checking......之后,这些线程才结束,但其他线程很快就结束了,不过最后,程序还是能正常完后但在服务器上运行,不一会不出现
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
这个错误,是什么原因到致呢还有一个问题想问,如果一个线程运行太久了,在线程池里面怎么去获取这个线程并结束它?
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1),
new ThreadPoolExecutor.CallerRunsPolicy()); //建立线程池for(int i=0;i<2000;i++){threadPool.submit(一个线程);
threadPool.submit(一个线程);
threadPool.submit(一个线程);
threadPool.submit(一个线程);}
try{
boolean loop = true;
do{
out.print("still checking......");
loop = !threadPool.awaitTermination(5, TimeUnit.SECONDS);
} while(loop);
}catch(Exception e){
}先寻立线程池,然后再提交很多线程,再用awaitTermination 检查全部线程运行完了没有,但现在有一个问题,我在自己的机子上运行,其中有三个线程一直不能结束,要等很久才能结束,也就是说,输出了很多次
still checking......之后,这些线程才结束,但其他线程很快就结束了,不过最后,程序还是能正常完后但在服务器上运行,不一会不出现
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
这个错误,是什么原因到致呢还有一个问题想问,如果一个线程运行太久了,在线程池里面怎么去获取这个线程并结束它?
ThreadPool threadPool = new ThreadPoolExecutor(2, 30, 2000,
TimeUnit.SECONDS, new ArrayBlockingQueue <Runnable>(1),
new ThreadPoolExecutor.CallerRunsPolicy())
TimeUnit.SECONDS, new ArrayBlockingQueue <Runnable>(2000),
new ThreadPoolExecutor.CallerRunsPolicy())
请问这个错误,到底有哪些原因?
out.print("JVM IS Total MEMORY:" + Runtime.getRuntime().totalMemory()/1024/1024+"M");
out.print("JVM IS USING MEMORY:" + (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024/1024+"M");
out.print("JVM IS FREE MEMORY:" + Runtime.getRuntime().freeMemory()/1024/1024+"M");查了也就50M左右,但tomcat有1G内存啊
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector URIEncoding="UTF-8" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="7777" redirectPort="8443"/>