Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


Charles Kerembe
returning a value from Threads
1 Answer(s)      a year and 11 months 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;
    }
});

}

Advertisement
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 Tutorials/Questions & Answers:
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
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
Advertisements
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 "
threads
threads  what are threads? what is the use in progarmming
Threads
)Separates the code from execution 3)Allows you to run your runnable from a Thread Pool
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
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
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
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
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
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 and events
threads and events  Can you explain threads and events in java for me. Thank you.   Java Event Handling Java Thread Examples
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
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
returning doubles with 2 decimals JAVA
returning doubles with 2 decimals JAVA  Hi all. I'm writing a program where users input the cost of an item (in the constructor), so for example, Item (string name, double cost, int qty) { ... } I have a method public double
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
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
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
Getting environment variable value from java
Getting environment variable value from java  Getting environment variable value from java
Sync Threads
Sync Threads  "If two threads wants to execute a synchronized method in a class, and both threads are using the same instance of the class to invoke the method then only one thread can execute the method at a time." This is what
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
threads in java
threads in java  iam getting that the local variable is never read in eclipse in main classas:: class Synex4{ public static void main(String args[]){ Test1 ob1=new Test1(); //local variable never read
Return Value From Event - Java Beginners
Return Value From Event  I would like to call a method that returns a value after an event has occurred and the value is determined by the event or listener. eg: public int mymethod() { static int value=0; KeyAdapter
Assign value from a <bean:write> tag to a variable
Assign value from a tag to a variable  I am calling a stored procedure from JSP page which needs an input parameter. This input parameter needs to get the value from bean write tag . How can i do that ?   Please go
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
How to save and get value from JSP
How to save and get value from JSP  Employee Name Time... 324 2012-12-12 save i want to save dis value jsp to action ...how can i get all value ..and store..how can its values goes
How to pass value from dijit.Tree to dijit.MenuItem - Ajax
How to pass value from dijit.Tree to dijit.MenuItem  Hi Friends, I... of 'Test' I want to show the value of that Node( which is comming from TreeNode... node whicl will apper on right click. What I have already done. From my server
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
passing value from javascript to jsp - JSP-Servlet
passing value from javascript to jsp  Hi... Is there any way to get the value from the javascript and print it on the current jsp page or print an array onto the current jsp page using javascript  Hi Friend, We
How to read value from xml using java?
How to read value from xml using java?  Hi All, I want to read value from following xml using java.. In <Line>,data is in format of key and value pair.. i want to read only values..could u plz help me in this?Thanks
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am new to jsp.In my applcation i having a problem. I am retrieving user payment from... information from database the i want to show cash radio button checked.How can i do
get value from multiple textbox in jsp
get value from multiple textbox in jsp  how to get multiple textbox value in another jsp? If i using the following code <%for(int i=0;i<3;i++) {%> <td>name<input type="text" class="name" id="name">
How to add value from sql server in dropdownlist
How to add value from sql server in dropdownlist  I have created a hospital management project using jsp servlet, where one form name is patient... id from other table like out patient, and this id will be stored dynamically
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
 

 

 

DMCA.com