Considerations for high concurrency for Java SE programs

Source: Internet
Author: User
Tags java se

Recently made a Java SE program. Use the thread pool to handle high concurrency tasks. There are query database operations during task processing, which results in very slow task handling. Then find the information on the Internet. The final solution is now to summarize the relevant considerations. First, on the thread pool considerations. For multiple tasks, the thread pool is best not to be public. The thread pool should be separated from the code for the thread pool


</pre><pre code_snippet_id= "547077" snippet_file_name= "blog_20141209_1_7940215" name= "code" class= "Java" >import Java.util.concurrent.executorservice;import Java.util.concurrent.linkedblockingqueue;import Java.util.concurrent.threadpoolexecutor;import Java.util.concurrent.timeunit;import Org.slf4j.Logger;import Org.slf4j.loggerfactory;public class Changethreadpool {private static Logger Logger = Loggerfactory.getlogger ( Changethreadpool.class);p rivate static Threadpoolexecutor executor = null; Declares a thread pool private static int coresize = 100; Number of core threads private static int maxSize = 150; Maximum number of threads private static final int keep_alive_time = 60; Life cycle public Changethreadpool () {}public synchronized void Syncinit () {executor = new Threadpoolexecutor (coresize, Maxsi Ze, keep_alive_time,timeunit.seconds, New linkedblockingqueue<runnable> ());} public static Executorservice getinstance () {if (executor = = null) {Logger.debug ("The >>>threadpool thread pool is empty! "); Changethreadpool pool = new ChangEthreadpool ();p ool.syncinit ();} return executor;}}
Second, database considerations

(1) For frequently found database operations preferably with cache, according to the actual situation must query the database, you must find

(2) The most important point is that the database CPU usage has been in the 100% situation. High concurrency causes the database CPU to persist because of frequent querying of the database. This situation is most likely caused by the absence of an index in the query statement, so you should check that all of your query statements have an index added to the Where condition. Adding an index will basically solve the problem.

Personal summary. Lest we write a similar program later and forget



Considerations for high concurrency for Java SE programs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.