Calling TS_TerminateAll from a thread

I started a UI in a thread in TS. There is a button on the UI. When I click on the button, the TS_TerminateAll will be called to terminate all execution. and then, it will call ProcessCleanup to close the instruments. However, I'm having some problem in the code in ProcessCleanup. Is it a proper way to call TS_TerminateAll in a thread?
Thanks
Eric

Matt,
Thanks for you response. There was actually no problem with terminating the sequence in a thread. I did not have "Allow Break While Terminating" enabled and I thought ProcessSetup.Main did not get executed during termination. I copied the ProcessSetup.Main to ProcessSetup.Cleanup and it was creating the problem since the cleanup code was executed twice. Anyway, there is no problem to terminate the sequence in a thread. Thank You.
Eric

Similar Messages

  • Call EJB from a thread , pb with lookup

    Hello,
    I have seen taht it is possible to call an EJB within a thread that can act as a client. But in my case when the thread calls the EJB method the lookup failed. I do exactly the same like if I call the ejb from an external client.
    In my case I have got the following architecture:
    one MDB which receive a message the pass the a "manager of thread" which select a thread and then this thread calls a session bean. Everything goes well until the thread call the EJB method and at this time the lookup fail. I call from local interface as I constructed my jar with all this components inside, i.e the MDB, the thread manager, threads and the session bean.
    I tried to call the session bean from the MDB in the same way I have done from the thread and in that configuration its ok.
    Is there a specific manner to lookup an ejb when we want to call it from a thread or simply this configuration is completely impossible?
    Thanks for any advice

    insert the following code before creating the InitialContext:
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

  • Threading- Can I call methods from specific threads or from all in a group?

    I've just recently started working with threads. I've done a lot of searching and reading but I haven't seen the specific questions I'm wondering answered. Of course, it's about communication.
    The amount of newly created threads that will exist is indefinite. Sometimes I'll have one, sometimes ten. So I'll just call them t1 - t9. When I create them, I add them to a ThreadGroup - tg.
    This project contains 2 class files, Main and ThreadClass. I'll post all of the code so you can see what I'm doing.
    public class Main {
        public static void main(String[] args) {
            for (int i = 1; i < 10; i++) {
                ThreadGroup tg = new ThreadGroup("tg1");
                Thread t = new Thread(tg, new ThreadClass("t" + i));
                t.start();
    public class ThreadClass extends Thread {
        public ThreadClass(String name) {
            super(name);
        public void run() {
            System.out.println("New Thread - " + getName());
            while (true) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    System.out.println("Exception: " + e);
        public void printText() {
            System.out.println("Printing text from " + getName());
    }So whenever a new thread is created, it prints "New Thread - [ThreadNameHere]". But I also have printText() in ThreadClass that has not been used yet and that is what I really want to accomplish. Is there a way to call printText() by the thread group (tg1 in this case) so it is executed across all threads that belong to the group? Is there a way to call printText() in a specific thread from my Main class, such as "t3"?
    Thank you for your help!
    Edited by: sdouble on Sep 9, 2008 10:10 AM - Fixed a typo

    Yes, usually you want to implement Runnable, not extend Thread. You're not adding new functionality to Threads or making some kind of more-specific version of them.
    You can get each thread in your ThreadGroup back out into an array by using one of the varients of Enumerate, but nothing stops you from just putting your objects (that implement Runnable) into an ArrayList or any collection of your own that you want to as you make them, and then later iterating over it and calling the method that you want.
    Something like this...
    public class MyThread implements Runnable {
       public void run() { ... }
       public void printStuff() { ... }
    public static void main(String[] args) {
       MyThread a = new MyThread();
       MyThread b = new MyThread();
       ArrayList threadList = new ArrayList();
       threadList.add(a);
       threadList.add(b);
       for(MyThread thread : threadLIst) {
          thread.printStuff();
    }

  • Calling getAppletContext() from a working thread.

    Hi guys,
    I'm new to Java so all apologies if I'm asking a stupied question.
    I have a simple applet that creates a working thread and I'm tring to call getAppletContext() from that thread.
    Obviously my working thread has no instance of the Applet class so it fails.
    I've try to create an instance of Applet, but I'm getting an error saying that the applet is not initialised.
    This is my code:
    class MyThread extends Thread
        String ThreadName;
        public MyThread(String threadName)
            ThreadName = threadName;
        @Override public void run()
            // ??? How to make the following line work ???
            getAppletContext().showDocument(new URL("javascript:alert(\"Calling from myThread\")"));
    public class MyApplet extends Applet {
         public void init()
            // The following line works!
            getAppletContext().showDocument(new URL("javascript:alert(\"Calling from MyApplet)"));
            Thread WorkingThread = new MyThread("Thread1");                                                                
            WorkingThread.start();
    }{code}
    Please help,
    Many thanks!
    Salvador                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Got it.
    I needed to pass the keyword this to the thread constructor and then use that....
    Many thanks!

  • IPhone - Trying to Update View from Separate Thread

    I am having trouble updating a view. My iPhone project is built from the Utility Application template. Upon startup, the Main View is loaded and some network communications are performed (on a separate thread). In response to the reply from the network, the toggleView method is called to switch to FlipSideView.
    This works (view changes) when I call toggleView from applicationDidFinishLaunching or by pressing the "i" button on the MainView. When I call toggleView after getting a response from the network, toggleView is called (as evidenced by a NSLog called within the toggleView method) but the View does not update.
    Does anyone have any ideas why this would happen?
    Could it have anything to do with the fact that I'm calling toggleView from another thread? If so, why would toggleView be called but not work?
    Thanks in advance,
    Daedalus
    - iPhone SDK Beta 8

    Update... I figured it out.
    To anyone else seeing this, when communicating between threads, you need to use the NSObject method performSelectorOnMainThread.
    Thanks.

  • JNI calls only work if sent from main thread?!?

    Hi,
    I searched through the forum for a couple of hours now, and found that a lot of developers seem to have problems with JNI and threads. However, I couldn't find a solution to my problem so far...hope you can help!
    We need to send requests to a DDE Server from our Java application. For that reason, we implemented a very small DLL using Delphi, which calls the DDE Server and returns the result as a string. Using JNI, we call this DLL from Java.
    Everything works fine, as long as we call the DDE Server (via JNI and the DLL) from the main thread of the Java application. But everytime we call it from another Java thread, our DDL reports that it can't get a connection to the DDE Server. This is especially awkward if you want to make calls as a reaction to GUI events, since then the call is sent by the Event Dispatch Thread of the Java runtime.
    This does not seem to be a multi-threading problem, since we do never send multiple requests at the same time. It simply depends on the thread, from which the call is sent.
    Any hints are appreciated very much.
    Thanks!
    Thilo

    We are a step further now...thus the problem to be solved changed a little bit.
    The former assumption, that connecting to the DDE server does only work from the main thread was false. It only seemed like that, because we called System.loadLibrary() to in the main thread to load the DLL . In fact, the connection to the DDE server works from any thread - you just have to make sure that System.loadLibrary() is invoked in this same thread.
    This means: if System.loadLibrary() is invoked in the Event Dispatch Thread, we can call the DDE Server from this thread, which is what we primarily wanted to do. So our problem is solved.
    Anyway, I made some more tests to find out, what happens if I start multiple threads, with each of them calling System.loadLibrary(). The result was, that only the first thread is successful. This means: the first thread, which loads the DLL is the only thread that is able to connect to the DDE server. All other threads won't get a connection.
    What could be the reason for that?

  • Independent stateful calls from different threads on one destination

    Hello SAP-Experts,
    i'm dealing with the problem on the Web AS to guarantee some independent stateful call sequences for different calling threads.
    One application running on a WAS (the WAS-app) is called by different clients to pass some data. The WAS-app has to distribute the data to another system by using one RFC-destination.
    As i have understood i have to guarantee thread-safe sessions for stateful calls from different thread by implementing a custom SessionReferenceProvider that binds the session to the thread. I have done this.
    My problem is to register my custom SessionReferenceProvider to the WAS environment. By trying i get the following error:
    [java.lang.IllegalStateException: SessionReferenceProvider already registered [com.sap.engine.sessionmgmt.jco.applib.impl.SessionReferenceProviderImpl]]
    Does anyone can tell me how to register the custom SessionReferenceProvider on a WAS?
    Thanks and greetings
    Robert

    Hi Robert,
    You can first try stopping a Java application named sessionmgmtjcoapplib from Star&Stop, then register yours sessionReferenceProvider again.
    Jian

  • Make Calls From Message Threads

    Regard From Sweden
    I love the phone, I've had it almost a week now and the communication possibilities are endless.  My job just got so much easier. Today however, I received an SMS from someone and then I was going to try to call them and realized that I could not do it. On my old Android, all I had to do was swipe the message. But that did not work here. I have been searching in Google and here under the following titles:
    “Make calls from message threads”
    “Ring from SMS”
    I have found nothing. Part of the problem is always coming up with the right search words. Surely one should be able to dial the number of a recieved SMS Thread  without having to memorize the number.  I also have had the problem of being unable to send longer SMS/Chat messages but I shall try turning off the WiFi as some have met with success with that measure
    My last problem is with Nokia’s City Lens. It worked fine the first 3 days that I had it, but now it won’t go past the Figure 8 page.
    Happy to report that battery life gets better and better with every charge. It's fun to be a telephone pioneer, I'm happy to be at the forefront for once instead of at the back. All my Iphone friends gawked at the new phone saying "What is that?"
    S-E

    Figured out the City Lens problem too. I have the phone i a Black Vegan Folio Wallet Case  even though the lens and camera are not covered by the case, the remainder of the backside is covered by a black plastic cóver. City Lens works out of the case, but not in it.

  • Calling System.exit() from multiple threads

    Hi,
    Why would calling System.exit() from multiple threads cause all the threads to block?
    Laith

    Thanks for your replies.
    I made further tests and the problem is actually not as I described it first.
    I'm using a shutdown hook that would stop all running threads if the program is stopped externally (using ctl-c for example) (I'm not using Thread.stop(), but setting a boolean value to false that would make the thread exit a while() loop in run()) .
    One of the running threads would call System.exit(-1) just before it would exit run().
    This thread is getting blocked if it is stopped by the shutdown hook.
    I know that this is a bad coding practice, bout would still appreciate an explanation to the reason why the thread is actually blocked by System.exit().
    Laith

  • Possible thread issues when calling java from C++/Delphi/C#

    Hi,
    We have a java API for one of our applications. This API has wrapper API's in C++, Delphi and C#. There are two main top level classes in te API - Client and Receiver. Both haave a receive() method.
    We used to ship JRE1.3 with the API installation - this was needed to suport the user applications. Recently we haev moved to java 1.4 as the least suported version.
    We have two ways of using the java API in our wrapper API's.
    Method one, we instantiate the client, and call client.receive(). There are no threads etc involved here. This is working fine.
    In the second method, we set a callback on the client, which starts a thread (in C++/Delphi or C#) which calls receiver.receive() and tries to get the message. This is failing.
    It fails at a line which simply says "DocumentBuilderFactory.newInstance()".
    This call has already been made when connecting the client and it is successful because we can see the client connected.
    Whether we do client.receive() or receiver.receive() in a thread, the code passes through this line.But is throwing the exception only when we come to it through a thread.
    Any ideas on what I need to watch out for when calling methods on a JVM from a thread in C++/Delphi or C#?
    Thanks
    Hari
    PS: I know we are using some really old versions, but thats needed and out of my control.

    Hi,
    I managed to solve this - finally!
    This is what was the cause in our case - should apply to all situations though.
    We had the Xerces classes packaged in a custom jar file along with other XML stuff we have. And this mega-jar was on the class path.
    We were running everything on Java 1.3 and it worked fine.
    But Java 1.4 wrecked all havoc.
    So here is what I did:
    1. I tried explicitly doing Class.forName() with the name of the Xerces class that was not found. I did this at the same point in the code where the exception was being thrown.
    2. The class was successfully loaded indicating that it was on the class path somewhere.
    3. Java 1.4 made some changes in terms of class loaders - so suspecting that, I tried printing out the System and the Context class loaders at the point where the exception was being thrown - the system class loader was a valid object, but context class loader was null
    4. We have another point in the code base where the exact same lines were used, and these are getting successfully executed even in the multi threaded situation - this is the start up sequence.
    5. I printed the two class loaders at this point - they are both valid objects, no nulls.
    With this, I narrowed down the scope and was convinced that the class loaders are the cause.
    A search on Google and after looking the the source code for Xerces, we realized that the Xerces API uses the Context Class Loader to resolve and load the DocumentFactoryImpl class - this change is from Java 1.4 onwards.
    In our case, the JNI AttachCurrentThread method called from C++/C# and Delphi was attaching the thread to the JVM, but each time the context class loader was null.
    We could not find anything on how we could make the method to put a non null context classloader.
    So, we changed all our JNI interfaces to do the following
    //attach the current thred
    jvm->AttachCurrentThread(...)
    //now get the system class loader and set it as the context class loader on the current thread
    //get things from the Thread class
    jclass thread = get the thread class
    jmethod currentThread = get the static method currentThread()
    jobject thread_object = get the current thread object into this
    jmethod setContextClassLoader = get the setContextClassLoader() method on the thread
    //get the SystemClassLoader
    jclass clsLoader = get the class for ClassLoader
    jmethodid getSysClsLoader = get the method ID for the getSystemClassLoader() method
    jobect sysClsLoader = get the system class loader by calling the above method
    //set the context class loader on the thread by calling set context class loader with the sys class loader as the argumentUnfortunately I don't have the code with me right now,otherwise would have shared the same.

  • Calling Report from Form Error ORA-06508

    Dear all,
    I want migrate from Fom6i to Oracle Developer Suite 10g (10.1).
    Folder Form = C:\APLIORA\IRS\FORM
    Folder Report = C:\APLIORA\IRS\REPORT
    I have modified file DEFAULT.ENV
    FORMS_PATH=C:\APLIORA\IRS\FORM;C:\APLIORA\IRS\REPORT
    i do not have problem call a form from form.
    but when i call report from form show error ORA-06508 : PL/SQL : could not find program unit being called ; -6508
    my procedure is
    PROCEDURE Call_Report IS
         list_id ParamList;
    BEGIN
    list_id := Get_Parameter_List('input_params');
    IF NOT Id_Null(list_id) THEN
    Destroy_Parameter_List(list_id);
    END IF;
    list_id := Create_Parameter_List('input_params');
    Add_Parameter(list_id,'MAXIMIZE',TEXT_PARAMETER,'YES');
    Add_Parameter(list_id,'ORACLE_SHUTDOWN',TEXT_PARAMETER,'YES');
    RP2RRO.RP2RRO_RUN_PRODUCT(REPORTS,'TESTREPORT.REP',SYNCHRONOUS,RUNTIME,FILESYSTEM,list_id,null);
    END ;
    Do I miss something ?
    Can any one help ?
    Thanks

    Hi,
    Thank you for your replay.
    The problem have solved.
    This my step :
    1. Install Windows XP SP2 and Form 10.1.2.0.2 on new pc.
    2. Install Jinit version 1.3.1.28.
    3. Create report server
    3. Compile form, report and pll
    4. call report from from with this procedure :
    PROCEDURE Call_Report (vFILENAME varchar2) IS
    report_id                Report_Object;
    ReportServerJob VARCHAR2(100);
    vc_rep_status      VARCHAR2(100);
    repsvr                          varchar2(21) := 'myserv';
    userid                         VARCHAR2(100);
    pass                          VARCHAR2(100);
    Host                    VARCHAR2(100);
    BEGIN
    userid          := Get_Application_Property(USERNAME) ;
    pass          := Get_Application_Property(PASSWORD) ;
    Host          := Get_Application_Property(CONNECT_STRING) ;
    report_id:= find_report_object('REPORT');
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_FILENAME,vFILENAME||'.jsp');
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_COMM_MODE,SYNCHRONOUS);
    SET_REPORT_OBJECT_PROPERTY(report_id,REPORT_SERVER,repsvr);
    ReportServerJob:=run_report_object(report_id);
    vc_rep_status := REPORT_OBJECT_STATUS(ReportServerJob);
    WHILE vc_rep_status in ('RUNNING','OPENING_REPORT','ENQUEUED', null)
    LOOP
    vc_rep_status:=REPORT_OBJECT_STATUS(ReportServerJob);
    END LOOP;
    IF vc_rep_status='FINISHED' THEN
    WEB.SHOW_DOCUMENT('/reports/rwservlet?report='||vFILENAME||'.jsp'||'&userid='||userid||'/'||pass||'@'||Host||'&destype=CACHE&desformat=PDF&paramform=yes','_blank');
    ELSE
    message ('Report failed with error message '|| vc_rep_status);
    END IF;
    END;
    Ok, but i have another strange error. I will post new thread.
    Thank you and regards
    Teguh S

  • Smartform Printing : Error in spool C call: Error from TemSe

    Hi! everybody,
    I am stating my problem as follows : I have to print a bar-code sticker of size 10 X 7 cms. I have worked on bar-codes before this also. This time the output from a smartform is to be given to a ZEBRA TLP 2844 printer. I initially encountered problems in printing. The data does not fit on to the page.
    After a lot of searching I found that ZEBRA was a partner of SAP and that a special device type needs to be created for output from a ZEBRA printer. I did this two times. Each time my steps were as described under.
    To create the device type I did the following :
    1. I finally found the driver from the ZEBRA website from http://www.zebra.com/id/products/global/en/utilities/sap_device_types.UtilityFile.File.tmp/Zebra_SAP_Device_Types.zip From this I uploaded the driver for 203 DPI zebra printer with IBM code 850 font file name "YZB200.PRI" into the transaction SA38.
    2. Then I created a new device ZEB10 in SPAD after assigning my format to the device.
    Thereafter, I tried to print my sticker. During this procedure, on selection of the new device type, the fonts automatically changed to ARIAL in the print preview. When I give the print command (Spool request : Print immed = X, Delete after output = X & New spool request = X) it gives an error message Error in spool C call: Error from TemSe.
    Since the output had not been issued, I opened the spool request to view its TemSe characteristics. Here I found
    Spool Attributes
    Output Device    ZEB10
    Format           ZTT               Format
    Doc. Category    SMART
    Recipient
    Department
    Deleted On       19.01.2011
    Authorization
    Output Attributes
    No. of Copies   1
    Priority              5
    SAP Cover Page Do not print SAP cover page
    OS Cover Sheet  Print as set at printer
    Requested           0
    Processed           0   With Problem                             0
                            With Error (Not Printed)                 0
    Storage Mode Print
    TemSe Attributes
    Object name           SPOOL0000013836
    Data type             ????????????
    Character set         0 -
    > Character set of dev type = 1162
    Number of parts       0
    Record format
    Size in bytes         0
    Storage location
    On seeing SP01
          Spool no.              Type                 Date        Time   Status   Pages               Title
           13836      Smartforms(OTF) 11.01.2011  07:32       +          0      SMART LP01 USERID
    I hope this data helps you help me. Please ask for more data if you wish. Also, I have searched vastly for this error on the net  have already come across the link http://help.sap.com/saphelp_45b/helpdata/en/d9/4a8f9c51ea11d189570000e829fbbd/frameset.htm but to no use. On the SDN, I have not found a similar thread and that is why I decided to post this problem here, hoping to find a solution. Kindly help.
    Regards,
    Manas

    Hi Manas,
    I am facing the same issue for one of my clients.
    Can you please share the solution with me if you have come out with it.
    Regards,
    Nirmal.K

  • Copy variable from one thread to another

    My program requires user to input a java file which contains the run() method.
    In the input file, user can declare variables and use those variables inside the run method. User also need to enter the number of threads to be spawned.
    The problem is how can I construct some method like "copy" which can copy the variable from one thread to another in my program? I can't do that since I don't know the name of the variables that the user inputted.
    I've tried this:
    class helloworld extends thread{
    void run(){
    String a="hello";
    String b="world";
    copy(0,1,a,b)
    class myProgram {
    Class c = Class.forName(fileName);         // file name of user's file     
    Thread t[] = new Thread[p];             // p is number of threads
         for (int i=0; i<p; i++){             // create threads      
                   t[i] = (Thread) c.newInstance();  
                   t.start();
    public void copy(int sourThread, int destThread, String s1, String s2){
    t[sourThread].s1=t[destThread].s2
    But it doesn't work. It said "cannot resolve symbol s1 and s2".
    please help. urgent. Thanks a lot in advance.

    You need to seriously reconsider what you're allowing the user to do. The short answer to your problem is to use a shared, synchronized associative array.
    However, since the user can specify any number of threads, you will have to resolve deadlocks, and the fact that you're asking this question suggests you will have problems doing so until you have read up on threads and shared variables in more detail. (I don't mean to be dismissive. Deadlocks and shared variables have to be customized to the application, i.e., you have to figure out just when each thread will need access to the variable, what kind of access, and when.)
    In the meantime, take a step back and take a look at the big picture.
    From what you've said, I would guess a common example of your application is that I want to be able to read file "foo.dat", uppercase each letter in the file, and write it out to "fooXXX.dat" where XXX reflects the thread number. And specify any number of threads I want.
    Threads would not be the best way to accomplish this. Do this serially.
    Alternatively, I could interpret your problem as in you need to create a main() function that's capable of reading someone else's dot-class file, clone the object and start it. In which case, why do you want to share variables? If the user did his job correctly, then his file will already contain shared variables (or copy them as appropriate). All you have to do is clone the object via the new keyword, then call start() in it.
    You cannot share something when you don't know what you're sharing.
    The third option is that you're doing this as an academic exercise (i.e., homework). Granted, yes, your professor may ask you to do things illogically just to prove they can be done. Unfortunately, we're not supposed to help you in that case. People who read this forum generally try to find logical and efficient ways of doing things.

  • How to refresh a JTable of a class from another thread class?

    there is an application, in server side ,there are four classes, one is a class called face class that create an JInternalFrame and on it screen a JTable, another is a class the a thread ,which accept socket from client, when it accept the client socket, it deal the data and insert into db,then notify the face class to refresh the JTable,but in the thread class I used JTable's revalidate() and updateUI() method, the JTable does not refresh ,how should i do, pls give me help ,thank you very much
    1,first file is a class that create a JInternalFrame,and on it there is a table
    public class OutFace{
    public JInternalFrame createOutFace(){
    JInternalFrame jf = new JInternalFram();
    TableModel tm = new MyTableModel();
    JTable jt = new JTable(tm);
    JScrollPane jsp = new JScrollPane();
    jsp.add(jt);
    jf.getContentPane().add(jsp);
    return jf;
    2,the second file is the main face ,there is a button,when press the button,screen the JInternalFrame. there is also a thread is beggining started .
    public class MainFace extends JFrame implements ActionListener,Runnable{
    JButton jb = new JButton("create JInternalFrame");
    jb.addActionListener(this);
    JFrame fram = new JFrame();
    public void performance(ActionEvent e){
    JInternalFrame jif = new OutFace().createOutFace(); frame.getContentPane().add(JInternalFrame,BorderLayout.CENTER);
    public static void main(String[] args){
    frame.getContentPane().add(jb,BorderLayout.NORTH);
    frame.pack();
    frame.setVisible(true);
    ServerSokct ss = new ServerSocket(10000);
    Socket skt = ss.accept()'
    new ServerThread(skt).start();
    3.the third file is a thread class, there is a serversoket ,and accept the client side data,and want to refresh the JTable of the JInternalFrame
    public class ServerThread extends Thread{
    private skt;
    public ServerThread(Sokcet skt){
    this.skt = skt;
    public void run(){
    OutputObjectStream oos = null;
    InputObjectStream ios = null;
    try{
    Boolean flag = flag;
    //here i want to refresh the JTable,how to write??
    catch(){}
    4.second is the TableModel
    public class MyTableModel{
    public TableModel createTableModel(){
    String[][] data = getData();
    TableModel tm = AbstractTableModel(
    return tm;
    public String[][] getData(){
    }

    Use the "code" formatting tags when posting code.
    Read this article on [url http://www.physci.org/codes/sscce.jsp]Creating a Simple Demo Program before posting any more code.
    Here is an example that updates a table from another thread:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=435487

  • How to call methods from within run()

    Seems like this must be a common question, but I cannot for the life of me, find the appropriate topic. So apologies ahead of time if this is a repeat.
    I have code like the following:
    public class MainClass implements Runnable {
    public static void main(String args[]) {
    Thread t = new Thread(new MainClass());
    t.start();
    public void run() {
    if (condition)
    doSomethingIntensive();
    else
    doSomethingElseIntensive();
    System.out.println("I want this to print ONLY AFTER the method call finishes, but I'm printed before either 'Intensive' method call completes.");
    private void doSomethingIntensive() {
    System.out.println("I'm never printed because run() ends before execution gets here.");
    return;
    private void doSomethingElseIntensive() {
    System.out.println("I'm never printed because run() ends before execution gets here.");
    return;
    }Question: how do you call methods from within run() and still have it be sequential execution? It seems that a method call within run() creates a new thread just for the method. BUT, this isn't true, because the Thread.currentThread().getName() names are the same instead run() and the "intensive" methods. So, it's not like I can pause one until the method completes because they're the same thread! (I've tried this.)
    So, moral of the story, is there no breaking down a thread's execution into methods? Does all your thread code have to be within the run() method, even if it's 1000 lines? Seems like this wouldn't be the case, but can't get it to work otherwise.
    Thanks all!!!

    I (think I) understand the basics.. what I'm confused
    about is whether the methods are synced on the class
    type or a class instance?The short answer is; the instance for non-static methods, and the class for static methods, although it would be more accurate to say against the instance of the Class for static methods.
    The locking associated with the "sychronized" keyword is all based around an entity called a "monitor". Whenever a thread wants to enter a synchronized method or block, if it doesn't already "own" the monitor, it will try to take it. If the monitor is owned by another thread, then the current thread will block until the other thread releases the monitor. Once the synchronized block is complete, the monitor is released by the thread that owns it.
    So your question boils down to; where does this monitor come from? Every instance of every Object has a monitor associated with it, and any synchronized method or synchonized block is going to take the monitor associated with the instance. The following:
      synchronized void myMethod() {...is equivalent to:
      void myMethod() {
        synchronized(this) {
      ...Keep in mind, though, that every Class has an instance too. You can call "this.getClass()" to get that instance, or you can get the instance for a specific class, say String, with "String.class". Whenever you declare a static method as synchronized, or put a synchronized block inside a static method, the monitor taken will be the one associated with the instance of the class in which the method was declared. In other words this:
      public class Foo {
        synchronized static void myMethod() {...is equivalent to:
      public class Foo{
        static void myMethod() {
          synchronized(Foo.class) {...The problem here is that the instance of the Foo class is being locked. If we declare a subclass of Foo, and then declare a synchronized static method in the subclass, it will lock on the subclass and not on Foo. This is OK, but you have to be aware of it. If you try to declare a static resource of some sort inside Foo, it's best to make it private instead of protected, because subclasses can't really lock on the parent class (well, at least, not without doing something ugly like "synchronized(Foo.class)", which isn't terribly maintainable).
    Doing something like "synchronized(this.getClass())" is a really bad idea. Each subclass is going to take a different monitor, so you can have as many threads in your synchronized block as you have subclasses, and I can't think of a time I'd want that.
    There's also another, equivalent aproach you can take, if this makes more sense to you:
      static final Object lock = new Object();
      void myMethod() {
        synchronized(lock) {
          // Stuff in here is synchronized against the lock's monitor
      }This will take the monitor of the instance referenced by "lock". Since lock is a static variable, only one thread at a time will be able to get into myMethod(), even if the threads are calling into different instances.

Maybe you are looking for