I am writing a multi-threaded program in which I get a java.lang.IllegalThreadStateException exception.
Any help would be appreciated.
here is my stack trace
Exception in thread "main" java.lang.IllegalThreadStateException at java.lang.Thread.start(Unknown Source) at GeoMain.main(GeoMain.java:18)
here is my code for the main class
public class TMain { public static void main(String[] args) { String Batchid="1,2,3"; String batch[]=StringUtils.split(Batchid,","); MultiThread gt=new MultiThread(); for(int i=0;i<batch.length;i++){ gt.setBatch(batch[i]); gt.start(); System.out.println("Thread started for "+batch[i]); } System.out.println("mainfinish"); } }
and here is my multithreading class
public class MultiThread extends Thread { private static Queue<String> queue = new LinkedList<String>(); private static Boolean isInUse = false; private void runcoder() { String batchid=null; BatchIdCreator bid=null; while(isInUse) { try { Thread.sleep(60000); } catch (InterruptedException e) { System.out.println("exception"); e.printStackTrace(); } } isInUse=true; synchronized(isInUse) { isInUse=true; batchid=queue.poll(); System.out.println(batchid); System.out.println(batchid); bid=new BatchIdCreator(batchid);
source share