> Dear All
> I'm fairly new to Java and have been attempting to get the
> java.util.concurrent package to work.
<snipped>
Rather than hand you the solution, I suggest you have a look at the text
of the errors.
> C:\test\ThreadPerTaskExecutor.java:5: test.ThreadPerTaskExecutor is
> not abstract and does not override abstract method
> execute(java.lang.Runnable) in java.util.concurrent.Executor
> class ThreadPerTaskExecutor implements Executor {
> ^
it says you need to override (ie write it yourself) method
execute(java.lang.Runnable)
You have a method
execute()
This is not the same!
> C:\test\ThreadPerTaskExecutor.java:9: cannot find symbol
> symbol : variable executer
> location: class test.ThreadPerTaskExecutor
> executer.execute(new test.ThreadOne());
> ^
This says that executer is unknown. Usually this means that you either
misspelled it, or forgot to declare it. A typical declaration is:
Object myObject = new Object();
after which you can use myObject.
A mistake a lot of newbies make is also that they forget Java is case-
sensitive. MyObject is not the same as myObject or myobject.
> C:\test\ThreadPerTaskExecutor.java:10: cannot find symbol
> symbol : variable executor
> location: class test.ThreadPerTaskExecutor
> executor.execute(new test.ThreadTwo());
see above.
One more thing: I don't think you'll need to implement your own Executor.
Instead, use something like this:
ExecutorService service = Executors.newFixedThreadPool(2);
service.execute(new ThreadOne());
service.execute(new ThreadTwo());
Let me Think - 29 Oct 2005 15:17 GMT
>> Dear All
>> I'm fairly new to Java and have been attempting to get the
[quoted text clipped - 43 lines]
> service.execute(new ThreadOne());
> service.execute(new ThreadTwo());
Thanks for the Tips Zero
Your right just giving the answer is no real help in the long term.
I was also looking in the Executor API on the sun site and not the
ExecutorService
I has seen the Runnable errors and has added the run() sections in thinking
this was then i did not known about the implementation of runnable
Only one part that puzzles me now why do i need the exit command?
Thanks
------------ file ThreadPerTaskExecutor.java --------------
package test;
import java.util.concurrent.*;
class ThreadPerTaskExecutor {
// class ThreadPerTaskExecutor implements Executor {
public static void main(String args[])
{
ExecutorService service = Executors.newFixedThreadPool(2);
service.execute(new ThreadOne());
service.execute(new ThreadTwo());
System.exit(0);
}
}
------------ file ThreadTwo.java --------------
package test;
public class ThreadOne implements Runnable {
public void run() {
System.out.println("External Thread one");
}
}
------------ file ThreadTwo.java --------------
package test;
public class ThreadTwo implements Runnable {
public void run() {
System.out.println("External Thread Two");
}
}
zero - 29 Oct 2005 19:38 GMT
> Thanks for the Tips Zero
> Your right just giving the answer is no real help in the long term.
[quoted text clipped - 27 lines]
>
> }
Actually, you need service.shutdown(); This tells the ExecutorService to
stop accepting new threads. When the threads it has at that point
(either running or in queue to run later) are finished, the
ExecutorService will shut down, which in your case will also shut down
the program since no more threads are running.
On Sat, 29 Oct 2005 10:35:53 +0100, "Let me Think"
<letmethink@unknown.com> wrote, quoted or indirectly quoted someone
who said :
>Any ideas what I have done wrong
Yes. You asked us to diagnose a program without showing it to us.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.