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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Charles Kerembe
returning a value from Threads
1 Answer(s)      2 years and 7 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
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
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
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
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
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
Getting environment variable value from java
Getting environment variable value from java  Getting environment variable value from java
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
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
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
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
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
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
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
 

 

 

DMCA.com