public void run() { while(true) { try { /*Object item =*/ queue.dequeue(); // Object item = queue.take(); // System.out.println("Processing: "+item); stat[1] = Math.max(queue.size(), stat[1]); if(queue.size()==0) { stat[0]++; if(queue.size()==0 && stat[2]!=0) { System.out.println("Queue is now empty."); break; } } } catch(Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); throw new RuntimeException(sw.toString()); } } } }).start();
/** * Cleanup on shutdown. */ public void dispose() { if(map!=null && !map.isEmpty()) { for(Iterator<IBlockingQueue<Message>> it=map.values().iterator(); it.hasNext(); ) { IBlockingQueue<Message> queue = it.next(); it.remove(); List<Message> items = queue.setClosed(true); for(int i=0; i<items.size(); i++) { items.get(i).getFuture().setException(new RuntimeException("Target disconnected.")); } } } if(platforms!=null && !platforms.isEmpty()) { for(Iterator<PlatformInfo> it=platforms.values().iterator(); it.hasNext(); ) { it.next().disconnect(); // Writes end time in DB. } } StatsDB.getDB().shutdown(); this.peers.dispose(); }
public void run() { synchronized(ThreadPool.this) { // If there are tasks and the last served task is too long ago if(running && tasks.size()>0) { Runnable task = tasks.peek(); Long start = enqueuetimes.get(task); if(start!=null && strategy.getCapacity()==0 && start.longValue()+maxwait<System.currentTimeMillis()) { addThreads(5); strategy.workersAdded(5); // System.out.println("Added threads due to starving task in queue: "+task+", "+strategy+", pool="+pool.size()+", parked="+parked.size()+", tasks="+tasks.size()); // System.out.println(tasks); } } } } }, maxwait, maxwait);
try waits.enqueue(this); monitor.wait();
ExecutionThread et = waits.dequeue(); MyMonitor monitor = et.getMonitor(); System.out.println("Restarting: "+et);
try this.task = ((Runnable)tasks.dequeue(strategy.getWorkerTimeout())); Long start = enqueuetimes.remove(task); long now = System.currentTimeMillis();
queue.enqueue(msg); msg.getFuture().get(new ThreadSuspendable(), 30000); // todo: how to set a useful timeout value!? sent = true;
this.tasks.setClosed(true);
platformentries[i].getValue().enqueue(new Message(SRelay.MSGTYPE_AWAINFO, new ByteArrayInputStream(awainfo2.getProperties()==null ? nopropinfo : propinfo))); map.get(id).enqueue(new Message(SRelay.MSGTYPE_AWAINFO, new ByteArrayInputStream(info2))); map.get(id).enqueue(new Message(SRelay.MSGTYPE_AWAINFO, new ByteArrayInputStream(info2)));
if(queue!=null) List<Message> items = queue.setClosed(true); map.remove(id); for(int i=0; i<items.size(); i++)