File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Threads/Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads/Arrays" Watch "Threads/Arrays" New topic


Alex Green

Joined: Nov 02, 2004
Posts: 4
while ((sline = br.readLine()) !=null)
StringTokenizer st=new StringTokenizer(sline, ",");
intA = Integer.parseInt(st.nextToken());
intB = Integer.parseInt(st.nextToken());
TrArray[intTr] = new Tr(intA, intB, tnl);

ThreadArray[intTr] = new Thread(TrArray[intTr]);

I am reading a file from the command line which contains several lines. I won�t know how many lines. Each line contains 2 integers separated by a comma. (intA, intB). A Tr object is created (consisting of the 2 integers & tnl (which is a tunnel object) & assigned to an array as each line is read. Then each object needs to be assigned to a thread & started.

Error occurs on the: ThreadArray[intTr] = new Thread(TrArray[intTr]) line
Error received is:
Cannot resolve symbol constructor thread Train

Any help would be appreciated

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Alex Green:
TrArray[intTr] = new Tr(intA, intB, tnl);

ThreadArray[intTr] = new Thread(TrArray[intTr]);
Does your Tr class implement Runnable? The Thread constructor you're using requires a Runnable object. Does Tr look something like the following?I don't know what you intend, but since you are not changing intTr in your loop, you'll be overwriting each Thread reference with the next one. The threads will still run, but you won't have references to them anymore (only the last one created).

On a side note, it's standard convention in Java to name all variables with initial lowercase letters (trArray and threadArray) so they can be distinguished from classes (Thread and Tr).
[ November 03, 2004: Message edited by: David Harkness ]
I agree. Here's the link:
subject: Threads/Arrays
Similar Threads
Extract all integers from a text file, how to do?
sting tokenizer in a loop(vv urgent)
Read integers from a file
Need help with read method