Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4588

Add start DGSM to Thread class

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.8-beta-3
    • 1.8-beta-4
    • groovy-jdk
    • None
    • jdk1.6u16
    • Patch

    Description

      Sometimes we need to split a huge task to some smaller tasks. The main thread should wait util all these tasks complete their tasks.
      The new start DGSM add support for this situation.

      Enjoy the patch

      The sample code is shown as follows:

      import java.util.concurrent.atomic.AtomicBoolean
      
      class Test extends GroovyTestCase {
          public void testThreadStart() {
              volatile AtomicBoolean thread1Done = new AtomicBoolean(false);
              volatile AtomicBoolean thread2Done = new AtomicBoolean(false);
      
              long thread1SleepMillis = 500;
              long thread2SleepMillis = 300;
      
              long begin = System.currentTimeMillis();
              Thread.start(
                      {
                          Thread.sleep(thread1SleepMillis);
                          thread1Done.set(true);
                      },
                      {
                          Thread.sleep(thread2SleepMillis);
                          thread2Done.set(true);
                      }
              );
              long end = System.currentTimeMillis();
      
              assert thread1Done.get() && thread2Done.get() && ((end - begin) < (thread1SleepMillis + thread2SleepMillis));
          }
      }
      

      Attachments

        1. Test.groovy
          1.0 kB
          Daniel Sun
        2. Test_v3.groovy
          1.0 kB
          Daniel Sun
        3. DefaultGroovyStaticMethods.java.v3.patch
          2 kB
          Daniel Sun
        4. DefaultGroovyStaticMethods.java.v2.patch
          2 kB
          Daniel Sun
        5. DefaultGroovyStaticMethods.java.patch
          2 kB
          Daniel Sun

        Activity

          People

            guillaume Guillaume Sauthier
            daniel_sun Daniel Sun
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: