This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 226288 - Broken RequestProcessor.Task.waitFinished with throughput 2
Summary: Broken RequestProcessor.Task.waitFinished with throughput 2
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 7.3
Hardware: All All
: P2 normal with 1 vote (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-18 17:43 UTC by Vladimir Voskresensky
Modified: 2013-07-17 02:40 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Patch with test (2.36 KB, patch)
2013-06-28 10:22 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Voskresensky 2013-02-18 17:43:36 UTC
Testcase to reproduce
    public void testRP() throws Exception {
        final RequestProcessor RP = new RequestProcessor("BrokenRP", 2);
        final AtomicBoolean outerDone = new AtomicBoolean(false);
        RequestProcessor.Task outerTask;
        outerTask = RP.post(new Runnable() {

                   @Override
                   public void run() {
                       final AtomicBoolean innerDone = new AtomicBoolean(false);
                       RequestProcessor.Task innerTask = 
                               RP.post(new Runnable() {

                                   @Override
                                   public void run() {
                                       System.err.println("Task1 start");
                                       try {
                                           Thread.sleep(5000);
                                       } catch (InterruptedException ex) {
                                           Exceptions.printStackTrace(ex);
                                       }
                                       System.err.println("Task1 finished 1");
                                       innerDone.set(true);
                                       System.err.println("Task1 finished marked");
                                   }
                               });
                       System.err.println("wait Task1");
                       innerTask.waitFinished();
                       System.err.println("after wait Task1 " + innerDone);
                       outerDone.set(innerDone.get());
                   }
               });
        outerTask.waitFinished();
        System.err.println("after wait Post " + outerDone);
        assertTrue(outerDone.get());
    }
Comment 1 Vladimir Voskresensky 2013-02-18 17:43:58 UTC
Jarda, please, have a look
Comment 2 anchialos 2013-02-20 07:48:12 UTC
I can confirm the bug with 
Product Version: NetBeans IDE 7.2 (Build 201207171143)
Java: 1.6.0_37; Java HotSpot(TM) 64-Bit Server VM 20.12-b01
System: Windows 7 version 6.1 running on amd64; Cp1252; de_CH (nb)

Workaround: 
Use a different RequestProcessor for the 'outerTask': in this case the call innerTask.waitFinished(); will work as expected.
Comment 3 Vladimir Voskresensky 2013-02-20 09:37:38 UTC
thanks, for now we use CountDownLatch.await instead of Task.waitFinished to workaround this bug.
Comment 4 Antonin Nebuzelsky 2013-06-26 10:44:33 UTC
Jarda, this needs to be handled by you. Thanks.
Comment 5 Jaroslav Tulach 2013-06-28 10:21:10 UTC
waitFinished() detects isRequestProcessorThread() in spite the task is running in another thread (of the same processor).
Comment 6 Jaroslav Tulach 2013-06-28 10:22:35 UTC
Created attachment 136454 [details]
Patch with test
Comment 7 Jaroslav Tulach 2013-07-10 12:25:49 UTC
ergonomics#957aa87a15ad
Comment 8 Quality Engineering 2013-07-17 02:40:20 UTC
Integrated into 'main-silver', will be available in build *201307162300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/957aa87a15ad
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #226288: In case of RP with throughput more than one, check whether the task is not running in other thread. If it does, we can still wait for it.