Java Thread return data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m6s
    New Member
    • Aug 2007
    • 55

    Java Thread return data

    Code:
    MovAvg run = new MovAvg(_symbol, this, SumDays.SMALL );
    threadExecutor.execute(run);
    Collection<Double> vl = run.getMovAvg().values();
            Iterator itr = vl.iterator();
            while(itr.hasNext()){
                System.out.println(itr.next());
            }
    This snippet generates, or at least tries to generate a Moving Average. The MovAvg is a Runnable class. I send in the symbol, the values ( a class of inherited treemap values) and the period of days ).
    In order to take back the results I try the to build a Collection and then generate an iterateion on the values of this collection.

    First: I have a Null exception, which I believe it has to do with the fact, that the thread might not have started yet? If so, how can I handle that the next step will be executed right after the execution of the thread ? Well what I don't see is how to "plug-in" wait, notify thing...

    Second: Is it right the way I am trying to collect the values? If I have secured that the thread will run before we reach to this point...

    Thank you...
  • Tassos Souris
    New Member
    • Aug 2008
    • 152

    #2
    Have a look at the java.util.concu rrent.Callable interface.
    It is similar to Runnable (in the sense that they can be executed by another thread), with the exception that Callable can return a result and throw a checked exception.
    Also, have a look at the Future interface that provides you with methods to check if the computations are complete, to wait, and to retrieve the result of the computation specified by a Callable.

    Take a look at the Java concurrent package API. There are some examples there.

    Comment

    • m6s
      New Member
      • Aug 2007
      • 55

      #3
      Se efharisto.. Mallon kanei tin douleia tou...alla prepei na to dokimaso vevea...

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        You are not allowed to use languages other than English in this forum.

        Comment

        • m6s
          New Member
          • Aug 2007
          • 55

          #5
          OK, thank you...Probably does the work but I should try first..though

          Comment

          • Tassos Souris
            New Member
            • Aug 2008
            • 152

            #6
            Originally posted by r035198x
            You are not allowed to use languages other than English in this forum.
            You don't promote internationaliz ation here :-)

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by Tassos Souris
              You don't promote internationaliz ation here :-)
              It's just a practicality; if the majority of the people online would've spoken Dutch, we'd all be speaking Dutch here ;-) English is the "Lingua Franca" of the net.

              kind regards,

              Jos

              Comment

              Working...