473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Java Thread return data

m6s
55
Expand|Select|Wrap|Line Numbers
  1. MovAvg run = new MovAvg(_symbol, this, SumDays.SMALL );
  2. threadExecutor.execute(run);
  3. Collection<Double> vl = run.getMovAvg().values();
  4.         Iterator itr = vl.iterator();
  5.         while(itr.hasNext()){
  6.             System.out.println(itr.next());
  7.         }
  8.  
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...
Jan 11 '09 #1
6 6547
Tassos Souris
152 100+
Have a look at the java.util.concurrent.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.
Jan 11 '09 #2
m6s
55
Se efharisto.. Mallon kanei tin douleia tou...alla prepei na to dokimaso vevea...
Jan 12 '09 #3
r035198x
13,262 8TB
You are not allowed to use languages other than English in this forum.
Jan 12 '09 #4
m6s
55
OK, thank you...Probably does the work but I should try first..though
Jan 12 '09 #5
Tassos Souris
152 100+
@r035198x
You don't promote internationalization here :-)
Jan 12 '09 #6
JosAH
11,448 Expert 8TB
@Tassos Souris
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
Jan 12 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
4
by: Robert Schneider | last post by:
Hi, I have got a problem inserting data of a file (both, binary and text) into a blob column. It is created with "Data BLOB(2G)" in the sql statement (so the name of the column is obviously...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
6
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
12
by: sandyw | last post by:
Exception in thread "main" java.lang.NullPointerException at company.Employee.inputEmployee(Employee.java:172) at company.Employee.main(Employee.java:267) which I got before... Can someone please...
2
by: josephx | last post by:
Hello, I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's...
2
by: ironpingwin | last post by:
Hi! I'd like to make few threads which will run in the same time in C++. I try to use boost library v 1.34.1 (it can't be newest, because I compile on remote machine, which is not...
1
by: lakshmiRam | last post by:
hi i have the below code to start bluetooth over PC to accept data from mobile but when i compile i will get the following errors i have widcom bluetooth stack and bluecove.jar and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.