Code example for TimeoutException

0
    } 
 
    public void put(Thread t, long timeoutMS) throws InterruptedException, TimeoutException
    { 
        if (!queue.offer(new WeightedQueue.Entry(t), timeoutMS, TimeUnit.MILLISECONDS))
            throw new TimeoutException("Failed to acquire request scheduler slot for '" + key + "'");
    } 
 
    public Thread poll()
    { 
        Entry e = queue.poll();
        if (e == null)
            return null; 
        stats.addNano(System.nanoTime() - e.creationTime);
        return e.thread;
    } 
 
    @Override 
    public String toString()
    { 
        return "RoundRobinScheduler.WeightedQueue(key=" + key + " weight=" + weight + ")";