Posts

Showing posts with the label threadpool

Multi Threading , concurency

 Threadpool Example Worker thread: package com.vasanth.java.concurrent; public class Workerthread implements Runnable { private String message; public Workerthread(String message) { super(); this.message = message; } @Override public void run() { System.out.println(Thread.currentThread().getName()+" : Start -> Message="+message); process(); System.out.println(Thread.currentThread().getName()+": End"); } private void process() { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } Thread pool: package com.vasanth.java.concurrent; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class TestThreadPool { public static void main(String args[]) { ExecutorService executor = Executors.newFixedThreadPool(5); for(int i=1;i<10;i++) { Workerthread workerthread = new Workerthread(""+i); executor.execute(workert...