Enable three threads and run them regularly.

Source: Internet
Author: User
Package COM. lesson. threadpool. example; import Java. util. concurrent. executorservice; import Java. util. concurrent. executors; import Java. util. concurrent. timeunit; public class threadpooltest {public static void main (string [] ARGs) {// create three thread pools executorservice threadpool =
Executors. newfixedthreadpool (3); // executors. newcachedthreadpool (); For (INT I = 1; I <= 10; I ++) {final int task = imo-threadpool.exe cute (New runnable () {public void run () {//.. for (Int J = 1; j <= 10; j ++) {try {thread. sleep (20);} catch (interruptedexception e) {// todo auto-generated catch blocke. printstacktrace ();} system. out. println (thread. currentthread (). getname () + "is loop of" + J +" Task
"+ Task) ;}}}) ;}system. out. println ("all of 10 tasks have committed"); // threadpool. shutdown (); // shutdownnow ();//.... executors. newscheduledthreadpool (3 ). scheduleatfixedrate (New
Runnable () {public void run () {system. Out. println ("Bombing") ;}, 6, 2, timeunit. Seconds );}}

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.