ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.22 by dl, Mon May 9 17:15:27 2005 UTC vs.
Revision 1.23 by dl, Tue Aug 23 12:50:00 2005 UTC

# Line 7 | Line 7
7   */
8  
9   import java.util.concurrent.*;
10 + import java.util.concurrent.atomic.*;
11   import junit.framework.*;
12   import java.util.*;
13  
# Line 1572 | Line 1573 | public class ThreadPoolExecutorTest exte
1573          }
1574      }
1575  
1576 +    /**
1577 +     * execute allows the same task to be submitted multiple times, even
1578 +     * if rejected
1579 +     */
1580 +    public void testRejectedRecycledTask() {
1581 +        final int nTasks = 1000;
1582 +        final AtomicInteger nRun = new AtomicInteger(0);
1583 +        final Runnable recycledTask = new Runnable() {
1584 +                public void run() {
1585 +                    nRun.getAndIncrement();
1586 +                } };
1587 +        final ThreadPoolExecutor p =
1588 +            new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS,
1589 +                                   new ArrayBlockingQueue(30));
1590 +        try {
1591 +            for (int i = 0; i < nTasks; ++i) {
1592 +                for (;;) {
1593 +                    try {
1594 +                        p.execute(recycledTask);
1595 +                        break;
1596 +                    }
1597 +                    catch (RejectedExecutionException ignore) {
1598 +                    }
1599 +                }
1600 +            }
1601 +            Thread.sleep(5000); // enough time to run all tasks
1602 +            assertEquals(nRun.get(), nTasks);
1603 +        } catch(Exception ex) {
1604 +            ex.printStackTrace();
1605 +            unexpectedException();
1606 +        } finally {
1607 +            p.shutdown();
1608 +        }
1609 +    }
1610 +            
1611   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines