I have a Java web application that works a lot with file conventions. Are . Code> Configuration and or In the config file and you should break it. Edit: can be transferred on the basis of your comments dedicated thread processing pool size according to your CPU count ( Edit 2: Links have been added to classes. Edit 3: in a project A sample method used. And you can use it like this: And in your Servlet
I am using Tomcat 6 as my topical container. When many requests are submitted, Tomcat is very hungry. I wonder how I can do tomatoes properly to reduce memory consumption. I'm also thinking about changing my servlet container.
What do you suggest? You can limit / limit the operating connection numbers to conf / server.xml
& lt; Executor name = "tomcatThreadPool" namePrefix = "Catalina-exec-" maxThreads = "16" minSpareThreads = "1" />
& lt; Connector Exporter = "tomcatThreadPool" port = "8080" protocol = "HTTP / 1.1" connectiontimeout = "20000" redirectPort = "8443" />
& lt; Connector port = "8080" Protocol = "HTTP / 1.1" connectiontimeout = "20000" redirectPort = "8443" maxThreads = '16' / & gt;
Rntaimkgetritaim (). Available Processor ()
) Then you can apply the number of pending actions to throttle (do not forget to specify
/ ** * A new thread is based on some properties * @ Param Pool Thread Control the number of worker threads in the pool * @ Param Pool Name Thread Pool name (for debugging purposes) * @ Param priority worker threads based on priority * @param capacity ExecutorService object of line used for the size of the task * @return * / private ExecutorService newPool (integer poolSize, string poolName, the last full Nk priority, int capacity) {int cpu = Runtime.getRuntime () availableProcessors () .; Executable service result = null; If (poolSize! = 0) {if (poolSize == -1) {poolSize = cpu; } If (Capacity & lt; = 0) {capacity = Integer.MAX_VALUE; } Result = new ThreadPoolExecutor (poolSize, poolSize, 120, TimeUnit.MINUTES, New LinkedBlockingQueue & LT; Runnable & gt; (capacity), New ThreadFactory () {@Override public Thread newThread (Runnable runnable) {Thread t = new Thread ( runnable); T .setPriority (priority); return t, (! executor.isShutdown ())}}, new RejectedExecutionHandler () {@Override public void rejectedExecution (Runnable r, ThreadPoolExecutor executor) {if {executor.getQueue () try {Put (.r);} hold (pre-emptive preemptive) {// leave}}}}); } Return results; }
executor service exec = newPool (-1, "converter pool" thread. NORM_PRIORITY , 500); ServletContext.setAttribute ("converter pool", exec);
executor service exec = (executor service) Srwletcontekst .getAttribute ( "converter pool"); Exec.submit (new runnab) {run public zero () {// your code goes for change here}}
Comments
Post a Comment