Home Answers Viewqa Design-concepts-design-patterns returning a value from Threads

 
 


Charles Kerembe
returning a value from Threads
1 Answer(s)      a year ago
Posted in : Design concepts & design patterns

Hello I have worker pattern that uses ExecutorService to schedule Thread execution but getting stuck at some point when returning a value using Future.I have code snippet below:

ExecutorService threadPool = Executors.newFixedThreadPool(1); 
      for ( int i=1; i<4; i++ ) { 
        threadPool.submit(new JobImpl("Job ", i));

Now this passes job and i as job and jobNumber to JobImpl class:

public class JobImpl implements Runnable {

    public String job;
    public int jobNumber;
   ExecutorService executorService = Executors.newSingleThreadExecutor();
    public JobImpl( String job, int jobNumber ) {

        this.job = job;
        this.jobNumber = jobNumber;
    }
    public String getJob() {

        return this.job;
    }
    executorService.execute(new JobImpl(job,jobNumber){
    public void run(){
    String j =Integer.toString(jobNumber);
    Deque<String> jdeque = new LinkedList<String>();

        jdeque.add(job+j);      
    }
});
    Future future = executorService.submit(new JobImpl(jdeque){
    public JobImpl call() throws Exception {
        return jdeque;
    }
});

}
View Answers

May 1, 2012 at 3:49 PM


I need to return the jdeque so that I can pass it on to another process but I have a problem with the submit(Callable) method.









Related Pages:
returning a value from Threads
returning a value from Threads  Hello I have worker pattern that uses ExecutorService to schedule Thread execution but getting stuck at some point when returning a value using Future.I have code snippet below: ExecutorService
Threads
)Separates the code from execution 3)Allows you to run your runnable from a Thread Pool
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
PHP Returning Values from Function
Returnig Values from function: From a function we can return values using... of the project. If we do not put any return statement then a NULL value is returned...(); echo "Value of \$var1= ".$var1."<br/>"; echo "
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
Synchronized Threads
Synchronized Threads       In Java, the threads are executed independently to each other. These types of threads are called as asynchronous threads. But there are two problems may
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...
why above code returning the value of squares is 82... even after returning an increnented value of squares... please help me...   public class d55 { int squares = 81; public static void main(String
Returning data from an MX item editor in Flex4
Returning Data from an MX itemEditor in Flex4: The ItemEditor control is a MX...;/fx:Script> <s:Panel title="Returning data from an MX... for return a single value to the control. You will use the editorDataField property
method returning null on JSP page.Plz HELP!!!
method returning null on JSP page.Plz HELP!!!  public String... it is returning null while the parameter values are successfully passed.while I am trying to print the sAddress value here it is printing correct here. I am new
method returning null on JSP page.Plz HELP!!!
method returning null on JSP page.Plz HELP!!!  public String... on the jsp page it is returning null while the parameter values are successfully passed.while I am trying to print the sAddress value here it is printing correct
Explain about threads:how to start program in threads?
Explain about threads:how to start program in threads?  import...; Learn Threads   Thread is a path of execution of a program... more than one thread. Every program has at least one thread. Threads are used
threads
threads  what are threads? what is the use in progarmming
interfaces,exceptions,threads
THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface... constants from an interface. * A class cannot inherit method implementations from...: Exception Handling in Java   Threads A thread is a lightweight process which
regardoing multi threads - Java Beginners
regardoing multi threads  Hi Please tell me how to declare global variables in main thread so that all other threads can use them and value will be available to all threads. Thanks
Threads - Java Beginners
Threads  hi, how to execute threads prgm in java? is it using...("/home/vinod/amarexamples:9090/" + "amarexamples/Threads/applet...("interrupt and return from run"); } } private void setPaused
Getting garbage value
, but whenever I'm using numeric value from 0010 to 0757 it is returning some garbage value. I dont have the idea what is going wrong. Please give me some idea to solve...("time").value=t1; } <%=t%>
Java - Threads in Java
Java - Threads in Java       Thread is the feature of mostly languages including Java. Threads... be increased by using threads because the thread can stop or suspend a specific
java threads - Java Interview Questions
for Java threads in the range of 1 to 10. Following is the constaints defined... priority from 1 to 10 in your program. Following example shows how to set
Shutting down threads cleanly,java tutorial,java tutorials
My thoughts on shutting down threads is based on ideas I gleaned from those two...;); } } For shutting down threads reading from sockets, we would do something like...Shutting Down Threads Cleanly 2002-09-16 The Java Specialists' Newsletter
Reading Value From console
Reading Value From console  In case of String data Type readLine method of DataInputStream class read complete line of the given string but the next method of Scanner class doesn't read the complete line of String. why
Reading Value From console
Reading Value From console  In case of String data Type readLine method of DataInputStream class read complete line of the given string but the next method of Scanner class doesn't read the complete line of String. why
Threads in Java
Threads in Java help in multitasking. They can stop or suspend a specific... selects the thread from Ready-to-Run pool and CPU allots the time slot and thread.... Waiting for notification: A thread here waits for notification from
Threads(suspend(),resume()) run time abnormal behaviour
Threads(suspend(),resume()) run time abnormal behaviour   class A implements Runnable { Thread t; A() { t... and prints nothing.But when i remove the // from the lines which i commented in run
Threads
Threads Basic Idea Execute more than one piece of code at the "same... time slicing. Rotates CPU among threads / processes. Gives.... Threads vs Processes Multiple processes / tasks Separate programs
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
values...it is returning NULL  <html> <head> <..." name="d" onclick="getAnswer('a')" value="a "/>dollar &nbsp; <input type="radio" name="d" onclick="getAnswer('b')" value="b "/>pound
how to access radio buttons selected in a servlet??...iam unable to retrieve values...it is returning NULL
values...it is returning NULL  <html> <head> <..." name="d" onclick="getAnswer('a')" value="a "/>dollar &nbsp; <input type="radio" name="d" onclick="getAnswer('b')" value="b "/>pound
passing value from javascript popup
passing value from javascript popup  How to take user input and pass that input value using popup in Javascript
Subtract a value in the database from java
Subtract a value in the database from java   Hi, i want to know how to subtract a value on a database. im using JDBC connection from access and i want to decrement the value of table "quantity" of 1 each time it passes a loop my
implementing an algorithm using multi threads - Java Beginners
data from one thread to another thread. I am posting my algorithm which needs to breakdown into two or three threads and need to implemented and need
StringTokenizer not returning proper result
StringTokenizer not returning proper result  I have this code... System.out.print("Enter the stack integers side by side with a space in between: "); StringTokenizer st=new StringTokenizer(br.readLine()); int a[]=new int[9000
Read the value from XML in java
Read the value from XML in java  Hi, i have an XML... the permissions on that file.So how can i read that value. This is little urgent.... <param name="file" value="D:/Lakki
export value in csv from jsp
export value in csv from jsp  Hi! i have creted a html form using javascript. i hv taken the array values in jsp. nw i want to pass these array values from jsp to csv file. so please help me how to send
Return Value from One Form
Return Value from One Form  I have two buttons in main form client and bank.when i click client button new form will open, in this dedupe button... value of dedupe form and use in bank form..how to do
Retrieve Value from Table - Hibernate
Retrieve Value from Table   Hai friend, I need help, How can i retrieve values From database using hibernate in web Application. As I new to hibernate I couldn't find solution for this problem.. Can anyone help please.. 
Retrieving attribute value from XML
Retrieving attribute value from XML  I have an XML as below to parse...; ..... But am not able to fetch the value of LoadTicketId attribute. My code...-values-from-a-nodel.shtml http://www.roseindia.net/xml/dom/GetData.shtml Thanks
store value in checkbox from gridview
store value in checkbox from gridview  Please check the error... = con.createStatement(); rst=st.executeQuery("select * from books...; <input type="submit" value=" DELETE "/>&nbsp;&nbsp
threads in java
threads in java  how to read a file in java , split it and write into two different files using threads such that thread is running twice
threads and events
threads and events  Can you explain threads and events in java for me. Thank you.   Java Event Handling Java Thread Examples
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
Min Value
Min Value   How to access min value of column from database table?   Hi Samar, You can access minimum value of column from database... min(id) from QuestionModel result_info"; Query query = session.createQuery
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
mktime()
GMT) and the time specified. The arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according... arithmetic and validation. It will automatically calculate the correct value
disadvantage of threads
is the disadvantage of threads?   hello, The Main disadvantage of in threads... disadvantage of Threads. Let?s discuss the disadvantages of threads. The global..., the other threads using the same memory location will be killed automatically

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.