why eclipse higlights this >>>. Callable<String> reverseTask = new Callable<String>;as an error
please help
6 3040
why eclipse higlights this >>>. Callable<String> reverseTask = new Callable<String>;as an error
please help
Because Callable is an interface, you can't instantiate it. I'm sure Eclipse tells
quite a bit more than just flagging it as an error; it also gives you the reason
why it is an error (which most of the time is the way to a solution).
kind regards,
Jos
- while(true){
-
ClientWorker w;
-
FutureTask task = new FutureTask (new MyCallable ());
-
ExecutorService es = Executors.newSingleThreadExecutor ();
-
es.submit (task);
-
try{
-
-
int result = task.get();
-
System.out.println ("Result from task.get () = " + result);
-
-
-
w = new ClientWorker(server.accept(), output);
-
Thread t = new Thread(w);
-
t.start();
-
} catch (IOException e) {
-
System.out.println("Accept failed: 4444");
-
System.exit(-1);
-
}
-
es.shutdown ();
-
}
-
}
-
now eclipse says cannot convert form object to int
here>>> int result = task.get();
now eclipse says cannot convert form object to int
here>>> int result = task.get();
That's because FutureTask is a generic class, i.e. you have to specify the type
of what shall be returned by the FutureTask. You didn't specify anything so the
return type is Object. An Object can not be cast to an int as Eclipse correctly
noticed.
kind regards,
Jos
- public class MyCallable implements Callable
-
{String toReverse;
-
JTextArea output = new JTextArea();
-
ServerSocket server = null;
-
public String call () throws java.io.IOException, InterruptedException {
-
-
ClientWorker w = new ClientWorker(server.accept(), output);
-
Thread t = new Thread(w);
-
t.start();
-
////Thread t = Thread.currentThread();
-
if (toReverse == null || toReverse.trim().equals(""))
-
throw new IllegalArgumentException("Set string to reverse");
-
if (t.isInterrupted()) return null;
-
char[] org = toReverse.toCharArray();
-
StringBuffer out = new StringBuffer();
-
if (t.isInterrupted()) return null;
-
for (int i = org.length-1; i>=0; i--) {
-
Thread.sleep(500);
-
out.append(org[i]);
-
if (t.isInterrupted()) return null;
-
output.setText(out.toString());
-
if (t.isInterrupted()) return null;
-
}
-
return out.toString();
-
}
-
now i get java.lang.OutOfMemoryError: unable to create new native thread when i try to run a client i think it's in MyCallable
[code]
public void listenSocket(){
server = mycallable.getServer();
mycallable.setToReverse(textField.getText());
while(true){
///ClientWorker w;
FutureTaskCallback task = new FutureTaskCallback (mycallable);
ExecutorService es = Executors.newSingleThreadExecutor ();
es.submit (task);
es.shutdown ();
}
}[code]
this code causes Outofmemory error
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Google Mike |
last post by:
After a lot of thought and research, and playing with FreeTDS and
InlineTDS, as well as various ODBC connections, I have determined that
the fastest and cheapest way to get up and going with PHP on...
|
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...
|
by: Developer |
last post by:
Hello All,
i have recently installed VS2005 and was trying to install SQL sever
2000.
I have Win XP' SP2. But when I tried installing, it only installed
client tools and not the database.
Can...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |