2 Threads issues. How to return data from a thread located in other class

I have 2 questions.
This is the context. From main I start one thread that does a little job then starts another thread and waits for it to end to continue.
1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
synchronized methods outside different classes (and the threads belongs to different classes).
2) From the main thread I start the Second Thread located in another class like this ClassName obj = new ClassName(arg); obj.start(); obj.join()
Is that correct for waiting for the created thread to finish ?

1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
synchronized methods outside different classes (and the threads belongs to different classes).Threads do not "belong" to classes. Class code executes in a particular thread. The class instances exist as long as something, somewhere, holds a strong reference to them.
So when you start a new thread, hold a strong reference to the object being executed by that thread. When the thread is done, retrieve your data from that object.
Even better, don't subclass Thread to create your objects. Instead, implement Callable, and use a ThreadPoolExecutor to execute it.

Similar Messages

  • How to pass Data from one form to the other

    Hi all
    Can any one suggest me how to pass data from one form to the other form, which i zoomed from the original one?
    I tried to do this by passing parameter in Event Procedure but i am getting error msg when i am opening the zoomed form.
    If any one of u have any idea, give me a reply
    Thank you
    Suhasini

    If you choose the second alternative you should erase these global variables after the second form is opened
    You can erase the global variable using:
    erase('global_var')
    Greetings,
    Sim

  • How to show data from one web site to other web site having diffrent domain.

    Dear all,
             i want to show the selected data from one web site to other web site.
    the location of the two web site is geographically seprated (and diffrent domain)
    Please tel me in how many ways it can be accomplished.
    If it can be done using jquery then please tel me the function or procedure to do it.
    Note: ( i have seen the above behavior in many web sites .
    like, i was purchasing some thing but finally declined,
    after that i visited some other web sites to gets some other data on other area
    , and i show my selected items of the first web site  on second website as advertisement.)
    i would like to know how these things are accomplished and how it can be done in asp.net.
    yours sincerely

    Hello,
    Thank you for your post.
    I am afraid that the issue is out of support range of VS General Question forum which mainly discusses
    the usage of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    Because your issue is about ASP.NET website programming, I suggest that you can consult your issue on ASP.NET forum:
    http://forums.asp.net/
     for better solution and support.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to copy data from one planning area to other planning area

    Hi ,
    I need to copy data from one planning area to other planning area, the MPOS for two planning areas are differant and  here my scenario is one planning area having extra key figures.
    First i need to release forecast data to CIP planning area and then,  i load the data from infocube  to MPS planning area and copy the data from CIP planning area. here both MPS and CIP planning areas having different MPOS .
    Please help me in this. Please give me the stepls i need to follow.
    Thanks in advance.
    Regards,
    Chandu

    Hi,
    You can use the transaction /sapapo/tscopy.
    In this you can configure your source plng area and destination plng area. You also have an option to map your KF. There is no problem if the MPOS are different as long as you are able to map the characteristics between the 2 MPOS.
    Alternatively, you can create an Infocube which shares common ground between the 2 planning areas and extract data from CIP plng area into the infocube and then copy teh data from infocube to MPS plng area using the the transaction /sapapo/tscube.
    Hope this helps.
    Thanks
    Mani Suresh

  • How to return data from Ejb as collection to Front End application.

    Hi,
    I am creating a J2ee application. Here i am accessing BAPIs using stateless session bean through JCO connection. Now the BAPI is returning a return Table and return Structure to the EJB.
    I have coded the following code in one of the Ejb Method as follows:
    JCO.Table returnTable = null;
    JCO.Structure returnStructure = null;
    JCO.ParameterList paramList = siteBAPI.getExportParameterList();
    JCO.ParameterList paramList2 = siteBAPI.getTableParameterList();
    returnTable = paramList2.getTable("SITE_SUBSITE_INSTL");
    returnStructure = paramList.getStructure("BAPIRET2");
    Now i want to sent this data( returnTable & returnStructure) to front end application where front end developer accessing this returned data using Jsp.
    My scenario is that , first i want to convert this returnTable & returnStructure in a single collection and then sent this collection to Front end.
    My aim is that , the front end the application should not receive the Data, using JCO.table Variable but as a single Collection.
    I am using NWDI-2004s sps10.
    i need urgent help on this issue and i would really appreciate if somebody can put the answer with some sample code on how to return the data as Collection.

    if you want to return a result, then you probably shouldn't be using a message bean. message beans for for asynchronous tasks. session beans for for synchronous tasks. thus it would make much more sense to have your jsp call the session bean directly.

  • How to return data from message bean ? ? ?

    Hi ... I have developed one simple application in JMS ...
    I have created one jsp page, one message bean and one remote EJB ...
    Now i m sending message to message bean .... i m also receiving message in message bean and i m calling one simple EJB method on that message called ...
    This all things are working well. But i wanted to return some data from that EJB to my JSP page .
    for example ...
    there is one sayHello() method in EJB which i m calling from message bean as i got message from JSP page .
    if i m printing that string in server log than its working well .
    now i wanted to return that string from that EJB method to JSP page.
    How can i achieve this ? can any one help me please ...
    actually i wanted to return whole XML file but recently as a newbie i m trying to just return hello world string .
    please help me for this problem ....
    thnks ...

    if you want to return a result, then you probably shouldn't be using a message bean. message beans for for asynchronous tasks. session beans for for synchronous tasks. thus it would make much more sense to have your jsp call the session bean directly.

  • How to return result from a Thread generically?

    Should be done using some form of callback class like below:
    Is this the right way of doing this or a better way especially trying
    to make it generic. What if I found the value from the Thread and want
    to pass that to some other class and do this generically?
    public interface Command {
       public void execute();
    public class ThreadClass extends Thread {
       private Command command;
       public ThreadClass(Command command) {
          super();
          this.command = command;
       public void run() {
           while (true) {
           if (xyz != null) {
              command.execute();
    }

    Should be done using some form of callback class like
    below:What should?
    Is this the right way of doing this or a better way
    especially trying
    to make it generic. Right way of doing what?
    What if I found the value from the
    Thread and want
    to pass that to some other class and do this
    generically?What value? What do you mean by "pass that to some other class"? What other class? What do you mean by "generically"?
    Can you post a (small but complete) example that actually demonstrates what you are trying to explain?
    public interface Command {
    public void execute();
    public class ThreadClass extends Thread {
    private Command command;
    public ThreadClass(Command command) {
    super();
    this.command = command;
    public void run() {
    while (true) {
    if (xyz != null) {
    command.execute();
    You are putting a thread into an infinite loop and wasting resources.
    So unless you intended on doing that (in which case you probably don't have particularly honourable motives so nobody here will want to help you), then whatever it is you're trying to do with this code, its certainly not the best way of doing it. Assuming its just a typo, then please, in future, test your code before you post it, and cut & paste it into the forums, and use the "Preview" button to check it looks okay.

  • How to return Values from Oracle Object Type to Java Class Object

    Hello,
    i have created an Oracle Object Types in the Database. Then i created Java classes with "jpub" of these types. Here is an example of the type.
    CREATE OR REPLACE TYPE person_type AS OBJECT
    ID NUMBER,
    vorname VARCHAR2(30),
    nachname VARCHAR2(30),
    geburtstag DATE,
    CONSTRUCTOR FUNCTION person_type RETURN SELF AS RESULT,
    CONSTRUCTOR FUNCTION person_type(p_id NUMBER) RETURN SELF AS RESULT,
    CONSTRUCTOR FUNCTION person_type(p_vorname VARCHAR2,
    p_nachname VARCHAR2,
    p_geburtstag DATE) RETURN SELF AS RESULT,
    MEMBER FUNCTION object_exists(p_id NUMBER) RETURN BOOLEAN,
    MEMBER PROCEDURE load_object(p_id NUMBER),
    MEMBER PROCEDURE save_object,
    MEMBER PROCEDURE insert_object,
    MEMBER PROCEDURE update_object,
    MEMBER PROCEDURE delete_object
    MEMBER PROCEDURE load_object(p_id NUMBER) IS
    BEGIN
    SELECT p.id, p.vorname, p.nachname, p.geburtstag
    INTO SELF.ID, SELF.vorname, self.nachname, SELF.geburtstag
    FROM person p
    WHERE p.id = p_id;
    END;
    My problem is, that if i use the member function "load_object" from my java app it doesnt return the selected values to the java class and i dont know why. I use the java class like this:
    PersonObjectType p = new PersonObjectType();
    p.load_object(4);
    There is a reocrd in the database with id = 4 and the function will execute successful. But if i try to use "p.getVorname()" i always get "NULL". Can someone tell me how to do that?
    Thanks a lot.
    Edited by: NTbc on 13.07.2010 15:36
    Edited by: NTbc on 13.07.2010 15:36

    CallableStatement =
    "DECLARE
    a person_type;
    BEGIN
    a.load_object(4);
    ? := a;
    END;"
    And register as an out parameter.
    Edited by: michael76 on 14.07.2010 05:01

  • How to read data from flatfile and insert into other relevant tables ? Please suggest me the query ?

    Hi to all,
    I have flat files in different location through FTP i need to fetch those files and load in the relavant table of the database.
    Please share me the query to do it ..

    You would need a ForEach Loop to iterate though the files. Initially the FTP task will pull the files from locations to a landing folder. Once thats done the ForEachLoop will iterate through files in the folder and will have a data flow task inside to transfer
    file data to tables.
    If you want a more secure option you can also use SFTP (Secured FTP) and can implement it using free WinSCP clinet. I've explained a method of doing it fo dynamic files here
    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html
    for iterating through files see this example
    http://visakhm.blogspot.in/2012/05/package-to-implement-daily-processing.html
    you may not need the validation step inside the loop in your case
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Return data from spark list itemrenderer

    Does anybody no how to return data from the itemrender for a spark list. say i had a checkbx in my itemrenderer how can I get that info back to my main component if its selected or not. I looked at datagrid and itemeditor but I really rather use a spark list. Thanks

    thanks I also found another way to doing it. A click handler on my list when that fires I can check if checkbx has been selected by doing event.target.document.mycheckBx.selected this will not work if using currentTarget cause it take the info from the itemRenderer. Now I understand the difference between currentTarget and target.
    not sure if this is a better way to access the data I think I might still just dispatch a event and do it your way.
    Its weird that mx:list has a editItemRenderer  and s:list does not
    thanks again TK

  • Return data from Java servlet in form of JSON encoded parameters in Javascr

    How to return data from Java servlet in form of JSON encoded parameters in Javascript handler function call?
    The same is implemented in php as the following
    echo "sT.handleAjaxResponse(";
    echo json_encode($response);
    echo ");";
    How to do the same in Java servlet?
    Thanks.

    With the rising popularity of JSON (especially with Ajax), support for it has started to appear in the Java community. I am not aware of any standardized approach yet, but expect it is likely we'll see that eventually. For now, you probably want to look at a third-party library such as the [JSON in Java Library|http://www.json.org/java/], Jettison, or [Java Tools for the JSON Format|http://jsontools.berlios.de/].

  • How to get data from textfield from an other class

    Hello everyone,
    I have a problem with an application I am writing for school. I want to get the data from a textfield into an other class.
    I have two classes: KlantGui and KlantMenuGui
    Some Codes from KlantGui:
    public String klantNummer;
    //knr
    knr = new JTextField(10);
    p2.add(knr);
    //getValue
    public String getValue() {
         return knr.getText();
    //getKlantNummer
    public String getKlantNummer(){
         klantNummer = getValue();
         return klantNummer;
    }And this one is from KlantMenuGui:
    private KlantGui kg = new KlantGui();
    //This is where I want the data to display
    String klantnr = kg.getKlantNummer();
    p2.add(new JLabel (" Klantnr: "));
    tf4 = new JTextField (10);
    p2.add(tf4);
    tf4.setEditable(false);
    tf4.setText(klantnr);I don't know why but it seems like the getValue() doesn't sends the data. For example if I write klantNummer = "2" instead of klantNummer = getValue(); it does work and I see 2 in the other class.
    Thanks!

    Does knr ever get populated?
    From the code below, you create an instance of a KlantGui, but this will have no values set, then straight away call getValue, which returns "", which is correct since the textfield for the instance of KlantGui just created would be empty?

  • Starting, returning data from, ending and restarting a thread

    I have a program that uses SWTCalender and threads. When I click a button (date), the event will cause a thread to be created, which will create a new shell that contains the calender. When I click on a date in the calender, I want the calender to pass the date back to the other shell at the same time. BUT, I also want it so when I close the calender thread, I can reopen it, as, when I try and reopen it at the moment, I get this error:
    Exception in thread "detailsscreen" java.lang.IllegalThreadStateException
         at java.lang.Thread.start(Unknown Source)
         at Practise.DetailsScreen$5.widgetSelected(DetailsScreen.java:558)
         at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
         at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
         at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
         at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
         at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
         at Practise.DetailsScreen.DetailsScreenRender(DetailsScreen.java:570)
         at Practise.Simian$1.run(Simian.java:24)I can create the other shell, but I don't know how to pass the data back to the main thread...
    http://img176.imageshack.us/img176/5738/picutrreve7.jpg
           final Thread datescreen = new Thread("datescreen") {          //thread for main details screen
                public void run(){
                        final Display datedisplay = new Display();
                        final Shell dateShell = new Shell(datedisplay);
                        dateShell.setBounds(12, 12, 180, 180);
                        final DateTime datechoose = new DateTime(dateShell, SWT.CALENDAR);
                        datechoose.setLocation(0, 0);
                        datechoose.addSelectionListener (new SelectionAdapter () { <<LISTENER TO THE CALENDER
                             public void widgetSelected (SelectionEvent e) {
                                  <I NEED TO SEND BACK THE DATA FROM THE THREAD HERE>
           button[4].addSelectionListener(new SelectionListener() {
              public void widgetSelected(SelectionEvent event) {
                     datescreen.start();
              }Thanks in advance!!

    You cannot 'restart' a thread; read the API documentation; you have to use a fresh new Thread object for that.
    kind regards,
    Jos

  • How configure a primavera web service to return data from the second database?

    Hi everyone,
    We have P6 with first WS deployed on a single server weblogic domain. The first WS return data from the first database instance.
    Then deployed advanced second WS on a separate weblogic domain server with a different port. Configured second WS with <WS2_INSTALL_HOME>/bin/dbconfig.sh, creating a new branch of a configuration that specifies a different second instance of the database. However, this configuration is ignored and second web services return data from the first database.
    We have one domain, which including next servers:
    Name / Host / Port / Deployments
    P6 / localhost / 0001 / P6(v8.3), p6ws1(v8.3)
    p6ws2 / localhost / 0002 / p6ws2(v8.3)
    Now we have two different file BREBootstrap.xml.
    P6 BREBootstrap.xml:
    <Database>
    <URL>jdbc:oracle:thin:@db1:1521:db1</URL>
    <UserName>pubuser</UserName>
    <Password>anycriptopass1</Password>
    <Driver>oracle.jdbc.OracleDriver</Driver>
    <PublicGroupId>1</PublicGroupId>
    </Database>
    <CfgVersion>8.330</CfgVersion>
    <Configurations>
    <BRE name="P6 Config_DB1" instances="1" logDir="anydir/P6EPPM/p6/PrimaveraLogs"/>
    </Configurations>
    p6ws2 BREBootstrap.xml:
    <Database>
    <URL>jdbc:oracle:thin:@db2:1521:db2</URL>
    <UserName>pubuser</UserName>
    <Password>anycriptopass2</Password>
    <Driver>oracle.jdbc.OracleDriver</Driver>
    <PublicGroupId>1</PublicGroupId>
    </Database>
    <CfgVersion>8.330</CfgVersion>
    <Configurations>
    <BRE name="P6 Config_DB2" instances="1" logDir="anydir/P6EPPM/ws2/PrimaveraLogs"/>
    </Configurations>
    ‘P6 Config_DB1’ and ‘P6 Config_DB2’ including Database property for 1 and 2 database respectively.
    How to configure a second web service to return data from the second database?
    Thanks in advance!
    Regards,
    Dmitry

    OK, so I got this to work this morning with Username Token Profile (with little help from Oracle Support).
    I followed your steps 1-4 but in step 2 I didn't add the -Ddatabase.instance=2 because I want to check to see if my code could swap between different instances.
    It appears for Username Token Profile to use Database Instance, you need to set it in the soap header.
    So my soap request looks like this:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <s:Header>
            <DatabaseInstanceId xmlns="http://xmlns.oracle.com/Primavera/P6/WS/Authentication/V1">2</DatabaseInstanceId>
            <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                <u:Timestamp xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' u:Id='uuid-327b6ed1-b26d-4a61-81d5-e326174c1961-3'>
                    <u:Created>2014-10-23T04:28:01.152Z</u:Created>
                    <u:Expires>2014-10-23T04:29:01.152Z</u:Expires>
                </u:Timestamp>
                <o:UsernameToken u:Id='uuid-327b6ed1-b26d-4a61-81d5-e326174c1961-3' xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>
                    <o:Username>admin</o:Username>
                    <o:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>password</o:Password>
                    <o:Nonce EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'>vJBQhCc28bAeszej7gOaiC2tVCQ=</o:Nonce>
                    <u:Created>2014-10-23T04:28:01.152Z</u:Created>
                </o:UsernameToken>
            </o:Security>
        </s:Header>
        <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <ReadProjects xmlns="http://xmlns.oracle.com/Primavera/P6/WS/Project/V2">
                <Field>ObjectId</Field>
                <Field>Id</Field>
                <Field>Name</Field>
                <Field>Status</Field>
                <Field>StartDate</Field>
                <Field>FinishDate</Field>
                <Field>DataDate</Field>
                <Filter>Id = 'EC00515'</Filter>
            </ReadProjects>
        </s:Body>
    </s:Envelope>
    This request pulled the project from the second instance.
    V/r,
    Gene

  • BDT *TFKB_Collect FM to return data from PAI

    Hi Experts,  hope you are going great.
    I am working on adding a couple of z fields in table TFKB, and letting users modify them thru tcode FM_FUNCTION.  I have added them to the table, and am wanting to edit/update them thru tcode FM_FUNCTION.  I was able to add z fields on the FM_FUNCTION through BDT (App Object FMFA in TCode BUS0).  However, the issue I ran into is that  there is no standard *TFKB_COLLECT function to pass zfield changes from my my z PAI Function Module.  The BDT guide says that the *tablename_Collect should be used to return data from Z PAI.  I am curious as to why SAP left out this module, and what are the options I have to return zfields back to SAP.  No FM under Function Group FM_FUNCTIONAL_AREA seem be doing this either.  We are running ECC 6.0. 
    (The "Get" module is available, but with a name different than the naming convention - "FMFA_DI_READ_DATA".)
    Thanks.

    The below mentioned code was answered by one of the members. I am copy pasting this here as i am not aware of how to attach other threads.
    use the below code to get spool data into internal table.
    data: begin of itab occurs,
    data(2000),
    end of itab.
    SUBMIT rspolst2 EXPORTING LIST TO MEMORY AND RETURN
    WITH rqident = 'spool number'
    WITH first = '1'
    CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
    listobject = mem_tab (table LIKE TABLE OF abaplist.)
    IF NOT mem_tab[] IS INITIAL.
    CALL FUNCTION 'LIST_TO_ASCI'
    EXPORTING
    List_index = -1
    TABLES
    listasci = itab
    listobject = mem_tab (LIKE TABLE OF abaplist)
    endif.
    by the above code you can get the data into internal table itab.

Maybe you are looking for