URGENT: How to run threads in sequence?

Dear experts, I am new to writing threads. I would like to know how to run threads in sequence? How do I know when a thread finishes its task?
In the following code, classes Process_A(), Process_B(), Process_C() and Process_D() are subclasses of Class Thread.
I'd like to know if I am using the join() function correctly? My intention is to wait for the previous process to finish before running the current process.
Could anyone kindly give me some solutions on how to run the processes in sequence?
Thanks!!
=============================================================
Thread process;
Vector process_names = new Vector();
process_names.add("a");
process_names.add("b");
process_names.add("c");
for(int i=0; i<process_names.size(); i++)
String process_name = (String) process_names.elementAt(i);
if(process_name.equals("a"))
process = new Process_A();
else if(process_name.equals("b"))
process = new Process_B();
else if(process_name.equals("c"))
process = new Process_C();
else if(process_name.equals("d"))
process = new Process_D();
timer = new javax.swing.Timer(1000, new ProcessListener());
timer.start();
// ProcessListener()
class ProcessListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
if(process!=null)
if(process.isAlive())
try
process.join();
catch(Exception ex)
ex.printStackTrace();
process.start();

just look at this simple example u will get to know how to use join method
This does exactly what u want
class callme
void call(String msg)
System.out.println("["+msg);
Try
Thread.sleep(1000);
catch(InterruptedException e)
System.out.println("interrupted");
System.out.println("]");
class caller implements Runnable
String msg;
Callme target;
Thread t;
Public Caller(Callme targ, String s)
target=targ;
msg=s;
t=new Thread(this);
t.start();
public void run()
target.call9msg);
class Synch
public static void main(String arg[])
Callme target=new Callme();
Caller ob1=new Caller(target,"hello");
Caller ob2=new Caller(target,"Synchronized");
Caller ob3=new Caller(target,"world");
Try
ob1.t.join();
ob2.t.join();
ob3.t.join();
catch(InterruptedException e)
System.out.println("interrupted");
waiting for dukes

Similar Messages

  • How to Run an IP Sequence in Background

    Hello:
    We call a sequence (containing a FOX formula) from a command button on a workbook and it keeps timing out.  Does anyone know how we could arrange to run this in the background and still have it triggered by the workbook button?
    We tried writing an exit function (ie new function type ) and then tried calling the original sequence using RSPLSSE_PLSEQ_EXECUTE but it kept short-dumping with an Uncaught Exception.  I'm guessing its not possible to call one (FOX) sequence from within another (EXIT) sequence due  conflicts in the buffer??
    Any help would be appreciated!
    Thanks...CM

    Hi Chris,
    your approach is not to bad. At first you need a variant for your planning sequence. if you have it you can run the planning sequence using the report RSPLS_PLSEQ_EXECUTE. Check if this works! Please note that you have to use a variant here. So you can not hand over variable values others than defined in the variant.
    Check if this is ok for you!
    If it works the next step is to create something that triggers your planning sequence for background processing. To achieve this you could write your own planning function type.
    In the execute method you could call a z-function module using the option starting new task. In the mentioned z-function you can start the report RSPLS_PLSEQ_EXECUTE using the ABAP statement submit.
    Please be aware that you need to design you application carefully. Otherwise you will have locking issues or the problem that the planning sequence is started and running several times by the user. So you should implement a mechanism to prevent this in your exit planning function type.
    As you can see, technically it is possible to decouple the execution of a planning sequence from the application, but you need to be very careful when implementing it, e.g. because of the problems mentioned above.
    But you are writing that the main reason for doing this is a performance issue. If I were you I would take a look at this first and see if I could model the application using less data, etc.
    Regards
    Matthias Nutt SAP Consulting Switzerland

  • Urgent - How to Run a FM using CATT script tool,

    Hi All,
    How to Run a FM using CATT script tool,
    Thanks in advance,
    KSR

    choose  type as "Function module test" (if you are in release less than 6.4 abap) after entering into t.code SCAT.
    Pl. refer to this documentation for creating function module test cases
    <a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCATTOL/CACATTOL.pdf">http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCATTOL/CACATTOL.pdf</a>
    reward if it helps
    Krishna

  • Urgent: how to run applet which connected to the servlet?

    hi frends:
    i have written an applet on the server side and it supposed to pass parameters to my servlet and retrieve some info from the servlet.
    i put both applet and servlet under tomcat../WEB-INF/classes. but when i run the applet from the web browser, there is no response from the servlet.
    could anyone help me to solve this problem?
    one more thing is i know that applet is able to connect to servlet, but how about java application? is it able to do so? if yes, is it also using URLconnection as applet? and how to run it?
    i will be very appreciate if anyone can help me... thanx a million.

    You can connect to the servlet from an application.There's a URL class in java.net that has an openConnection method. Then cast the return to an HttpURLConnection and use setMethod to set up as a post request.This may be the default if you call setDoOutput(true) on the URLConnection. Then you'll need to get an OutputStream and write properly formatted form POST data to it. It's also possible to encode your data on the URL, even when using the POST method, and this may be easier when doing it programmatically from an application. To send a get request you can append the name-value pair at the end of the url.

  • Urgent: How to : Multi-threaded Client??

    Hi,
    I have socket connection and was using single client thread untill now. But now requirements need to have multi-threaded client. Can any one pl. help me how to send messages thru' one thread and receive messages thru' another thread using same connection?? I urgently need help on this.
    thanx

    Create aclasses derived from thread for use by receiving
    Pass the socket to that class's constructor
    In the receivers thread's run method just in a while loop call read, or readObject, or whatever
    Just send in the regular thread.

  • URGENT-How to run command in java application???

    URGENT!
    i would like to run command to invoke some applications (like invoke application using command line in DOS) in my java appication.
    Do anyone know how to do this? Thanks a lot.

    This question has been asked upteen times.
    ok the code is
    for win95
    Runtime.getRuntime().exec( "start c:\\tmp.txt" );
    for win 2000
    Runtime.getRuntime().exec( "cmd /C startc:\\tmp.txt" );
    //change the file to your desire file..
    i am not so sure about win98, sorry...

  • Urgent-how to run 'alter system kill session 'sid, serial#' in form 6i ?

    I want to write a procedure in Form 6i so that user can kill the session by herself.
    I know kill session sql is 'alter system kill session 'sid, serial#'', however, I fould that I can only run it it sql plus screen, how can I run it in Form or in Stored procedure?
    Urgent....Please!

    try using Forms_ddl('alter system......'); in the forms. it will execute the dml statements in the form.
    zaibi.

  • In sm37, how to run job in sequence ?

    Hello,
    In sm37, how  run job1 and job2 in sequence ?  Our requirement is ,once the job1 is excuted then only job2 should be fired.
    Regards,
    Rachel

    You have to modify the Job2 & in the "after job" box you have to enter "Job1" ...
    Please refer to this for details: [http://help.sap.com/saphelp_nw70/helpdata/EN/20/2d513897110872e10000009b38f889/content.htm]
    But note that you cannot schedule job2 as "periodic" in this case.
    If you want to do so you have to use "SAP Events".
    BR,
    Suhas
    Edited by: Suhas Saha on Apr 19, 2010 11:17 AM

  • How to run threads in background

    hi everyone!
    I need some hints on my problem!
    I have an application with some working threads. When the user minimizes the app the app should go to the system tray and the threads should keep working.
    I already know how to put an icon with popup menu in the systray. Now, how can I run the working threads in background?
    Can anybody help me?
    C u,
    Filipe

    I said that because as far I understood the following code it just creates an icon and popup menu, right?
    So, when the user minimizes the app I need to kill it, create the icon and popup menu and leave the threads working.
    public class SystemTrayDemo extends JFrame
         private static final long serialVersionUID = 1L;
         public SystemTrayDemo()
              JPopupMenu menu = new JPopupMenu("Menu");
              JMenuItem menuItem1 = new JMenuItem("Menu1");
              JMenuItem menuItem2 = new JMenuItem("Menu2");
              JMenuItem menuItem3 = new JMenuItem("Menu3");
              JMenuItem menuItem4 = new JMenuItem("Exit");
              menu.add(menuItem1);
              menu.add(menuItem2);
              menu.add(menuItem3);
              menu.add(menuItem4);
              menuItem4.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent evt) {
                        System.exit(0);
              ImageIcon icon = new ImageIcon("database.png");
              TrayIcon trayIcon = new TrayIcon(icon, "Hello System Tray", menu);
              SystemTray tray = SystemTray.getDefaultSystemTray();
              tray.addTrayIcon(trayIcon);
         public static void main(String[] args)
              try
                   javax.swing.UIManager.setLookAndFeel("com.sun.java.swing. plaf.windows.WindowsLookAndFeel");
              catch(Exception e)
                   System.out.println(e);
              new SystemTrayDemo();
    }}

  • URGENT: How to run a Java program from a different directory?

    Hi.
    How do I run a Java program from a directory that the file is not located in? So lets say im in c:\Java. But the file is in c:\Java\abc\efg\.
    What would be the command to run the Java file from c:\Java.
    I can't remember it and I need it asap.
    Cheers.

    If the class you are trying to run is MyApp.class, try
    c:\Java\>java -cp abc\efg MyAppThe actual classpath you specify will depend on whether or not MyApp.class is in a package (I've assumed it isn't) and whether or not any 3rd party jars are involbed (I've assumed not).
    Edited by: pbrockway2 on Apr 1, 2008 6:42 PM
    The command arguments read as "Run the MyApp class using as a classpath abc\efg relative to here (c:\Java)".

  • Urgent: How to run Multiple Applets from a URL

    Hi,
    I am developing an applet that needs memory more than 64MB and I have used -Xmx to set it to 128 MB.
    On my web page, I have 3 applications that use the same JAR file of the applet, but the problem is all applets are opened/loaded in same heap space by JVM. So, when I load first applet, it uses 80 MB and when I start 2nd applet, after using 40 MB, it throws OutOfMemory exception.
    Is there a way to start each applet with fresh 128 MB heap space rather than all applets sharing 128 MB heap space?
    Thanks,
    Ajit

    That's some hefty requirements for an applet. I believe that the only way to do the Xmx thing on the client side is to have them manually add it in the JVM arguments section of the Java Plugin Control Panel.
    The browser/plugin is going to use the same JVM to run all 3 applets in a page. I've never seen a way to tell it to do otherwise. The only separation is the applet contexts, but that is more of a security manager grouping thing.
    Maybe you should look into how you can better manage your data so you don't need so much memory.

  • Urgent-How to run the BW Statistics Query?

    Hi
    we have recently installed the Techincal Content queries.We have about 43 queries Now i have to check the queries in Q before i approve them for transport to Prod.
    I would really appreciate if anybody could give me a step by step procedure on how to test it.
    Thanks

    Hi Kiran,
    I would suggest that you do some tests for a period of 1 week to ten days. In this period you should run some daily loads on your structures for which the Statistics has been activated.
    Then on a daily basis you can run your queries like 0BWTC_C10_Q314 - WHM Use per InfoSource. In this query based on the selection of your infosource you can get the following informations
    1. Different request ID's loaded into the Data targets.
    2. the information on Data targets, like which are the data targets linked to the info source.
    3. Date and time when loading into the Data targets happened.
    4. Number of records transferred and added into the Data target...and much more.
    After getting this Info you can check in the system if your test loads which you are doing on a daily basis matches this information or not.
    You can do similar tests on Query usage for example where you can ruin certain queries in your system and see if the information is reflected in your queries.
    For this u can use 0BWTC_C10_Q011 - OLAP Use per User.
    Also donot forget that to refresh the statistics information you have to always reload your statistics cubes and this you should do via a process chain and schedule it atleast twice in a day so that every morning you get the refreshed information as to what was loaded the previous day.
    You can also get a lot of relevant information from this link
    http://help.sap.com/saphelp_bw30b/helpdata/en/d1/e81c3b85e6e939e10000000a11402f/frameset.htm
    Hope this helps!!
    Assign points if it does:-)
    Regards,
    Jadeep

  • Urgent:How to run BSP Application on Emulator Pocket PC2003 (mobile device)

    Hii Experts
    We are developing a BSP application on BI in HTMLB.When we run this application on Emulator Pocket PC2003 (mobile device), it is just showing the header,and rest of the page is blank.It is not showing any data.
    Can there be any problem with the used HTMLB tags?
    If HTMLB file not converting properly to HTML file,how can i locate the error?
    Where and how can i find solution to this problem?
    Please help me in solving this problem ASAP.
    Thanx to experts in advance.
    Regards
    Varun

    Hi,
    Have a look at the mobile extension:
    http://help.sap.com/saphelp_nw04/helpdata/en/e6/103b3b4c003416e10000000a114084/frameset.htm
    Alternatives are Web Dynpro or create you own HTML which needs to be conform http://www.vnunet.com/vnunet/news/2159256/w3c-drafts-mobile-web
    Eddy

  • Urgent: How to run a form

    Hello,
    I am using Form Builder 6i. How can I run a form without running it from Form Builder. It is a client/server form.
    Thank you very much!

    Alternatively, you can select the Forms Runtime shortcut , found in the Developer/2000 program group.....(Start->Programs->Developer/2000->Forms->Forms Runtime)....
    In the pop-up window , just select the runtime file .... and write down the username/password/database....
    Regards,
    Simon

  • URGENT: How to Run an existing Oracle apps page in Jdev 10g

    Hi All,
    I have downloaded Jdeveloper 10G with OA Extension from the patch 5856648. I am able to successfully run the "test_fwktutorial.jsp" and "HelloWordPG.xml". I need to customize an existing Oracle apps page for one of our client requirement. I've done the following:
    1. Downloaded the BC4J components of the page which include xml and .class files from $JAVA_TOP/oracle/apps/ego and placed it in myproject( C:\p5856648_R12_GENERIC\jdevhome\myprojects) and also myclasses( C:\p5856648_R12_GENERIC\jdevhome\myclasses) folder of my jdeveloper.
    2. Downloaded the mds PG.xml from $APPL_TOP/ego/mds and placed it in C:\p5856648_R12_GENERIC\jdevbin\jdev\oamdsxml\fwk with the appropriate folder structure.
    I need to extend one of the VO and one of the controllers from the above standard oracle files. But since there are only .class files in the server, if I open the .class files, the methods are missing in those files. By decompiling the class files also, during run time it gives me error.
    What is the right approach and steps to use the existing Oracle apps files. Is there some way in Jdeveloper where we can set the source of java file with compiled .class files. I'm not able to work in the Jdeveloper for this customization. Please could some one help.
    Thanks & Regards,
    Anita

    1st thing to make sure is that you want to do changes for an R12 instance because that's this version of Jdev is provided for.
    Class files are required in myclasses folder only. Also page xml files should be in myprojects folder with the appropriate folder path.
    Decompiling class files are only way to work with them.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • SAP ECC 6.0 System Performance

    Gentlemen, Please advise me with the following scenario, which is Iu2019m facing a problem with system performance, My system configuration is:      SAP ECC 6.0 Database System:          Oracle 10.2.0.2.0. Server Configuration:     Power 6 Processor

  • Letterboxing when using 16:9 footage in 4:3 project...

    Hi, I have a project here that is DV-NTSC-720x480-4x3. Now when I import footage that is 720x480 / 4x3 it is displayed properly e.g. this file: Codec : MPEG-2 Video Codec profile : Main@Main Codec settings/Matri : Standard Bit rate : 9800 Kbps Bit ra

  • How to get my Image to outline correctly in an assigned DIV

    The last question I posted here regarded placing DIVs within parent DIVs and getting them to outline correctly. This question is actually strinkingly similar, and hence my hesitance to post it. I feel I'm looking over something extremely obvious, but

  • Is there a way to export at a target file size?

    I need to export at <10Mb. For now I've been exporting at descending quality levels until I get each picture to come in just under 10Mb, but this is very time consuming. Is there any way to do this straight out of Aperture? I see LR5 now has an optio

  • Unable to update Software through phone in Nokia A...

    Dear Nokia, I checked today that there is a software update available for my Asha 200. I downloaded the software through the option given in the phone. The software was downloaded successfully but when i tried to install the software, phone prompted