Passing parameters to run() method of a thread?

hello ppl
is it possible to pass any parameters to the run() method of a thread
moreover if i create a thread foo the only method that can run is run() ? i know that i can have more methods and just call them via run().
i mean that if i create the constructor of the foo class then first the constructor will be called and then the run() method.but in this way only the code inside run() will run autonomously(meaning that for example i'll be able to press a button of my gui).
thx in advance. =)

not sure I understand the question completely, but you can try the following. Set up whatever arameters your requiring as member variables of your Runnable. Overload the run() method with parameter list you need. In this overloaded method initialize the member variables in your runnable, which can be used in the run() , no arg version,/ Then the last line of the overloaded version call run(), again no-arg version.
Not really familiar with thread programming, but I dont see why this wont work.
Hopefully I understood the question correctly, and this is of some help...

Similar Messages

  • Passing Parameters via Post Method from Webdynpro Java to a web application

    Hello Experts,
    I want to pass few parameters from a web dynpro application to an external web application.
    In order to achieve this, I am referring to the below thread:
    HTTP Post
    As mentioned in the thread, I am trying to create an additional Suspend Plug parameter (besides 'Url' of type String) with name 'postParams' and of type Map.
    But when I build my DC, I am getting the same error which most of the people in the thread have mentioned:
    Controller XXXCompInterfaceView [Suspend]: Outbound plug (of type 'Suspend') 'Suspend' may have at most two parameters: 'Url' of type 'string' and 'postParams' of type 'Map'.
    I am using SAP NetWeaver Developer Studio Version: 7.01.00
    Kindly suggest if this is the NWDS version issue or is it something else that I am missing out.
    Also, if it is the NWDS version issue please let me know the NWDS version that I can use to avoid this error.
    Any other suggestion/alternative approach to pass the parameters via POST method from webdynpro java to an external web application apart from the one which is mentioned in the above thread is most welcome.
    Thanks & Regards,
    Anurag

    Hi,
    This is purely a java approach, even you can try this for your requirement.
    There are two types of http calls synchronous call or Asynchronous call. So you have to choose the way to pass parameters in post method based on the http call.
    if it is synchronous means, collect all the values from users/parameters using UI element eg: form and pass all the values via form to the next page is nothing but your web application url.
    If it is Asynchronous  means, write a http client in java and integrate the same with your custom code and you can find an option for sending parameters in post method.
    here you go and find the way to implement Asynchronous  scenario,
    http://www.theserverside.com/news/1365153/HttpClient-and-FileUpload
    http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html
    http://digiassn.blogspot.com/2008/10/java-simple-httpurlconnection-example.html
    Thanks & Regards
    Rajesh A

  • Is it possible to throw an exception from run method of a thread?

    Is it possible to throw an exception from "run method of a thread"(implemented as runnable implementation)?
    Is it advisable to do so?

    Is it possible to throw an exception from "run method
    of a thread"(implemented as runnable
    implementation)?Yes, an unchecked one. Runtime exceptions.
    Is it advisable to do so?If you mess up it happens automatically. But basically: no.

  • How I can pass parameters by POST method?

    How I can pass parameters by POST method?
    I use URL Template iView. I checked Requested Method - POST, but when I started the iView the program says:"It's a GET method!"
    I use httpServletRequest.getMethod()in the program.
    Environment: EP6 SP2
    Thank's! 

    Hi Kremena,
    the OSS stands for "Online Service System" - service.sap.com - messages or directly: service.sap.com/message.
    Hope it helps
    Detlev

  • Passing parameters to a method

    I am passing objects to another method.
    I do some changes to them and expect the changed objects to be available in the calling method ( since they are supposedely passed by reference) when the execution is returned to it. However, I don't get the changed objects but rather the old ones, before the method execution.
    Can someone explain?
    Thanks,
    Boris.

    I do some changes to them and expect the changed
    objects to be available in the calling methodIf you modify an object passed to a method, then the changes made to that object will be visible as soon as they are made.
    If you change the parameter so that it references some other object, this will NOT be seen in the calling method.
    You can "fake" it by putting the object in question in an array and passing the array. Better though is to just not expect methods to be able to change references they are passed to point at some other object.

  • Pass parameters into a method from other methods.

    I m testing  2 related applications with coded ui test and wanna pass a parameter from one method into another.
    how can i do that?
    Thank you in advance.

    Hi mah ta,
    Could you please tell us what about this problem now?
    If you have been solved the issue, would you mind sharing us the solution here? So it would be helpful for other members who get the same issue.
    If not, please let us know the latest information about it.
    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 write uninterruptable blocks of code in the RUN method of a THREAD?

    Hello people,
    It is better I explain my problem with example code
    public class MyThreadClass implements Runnable
    //some definitions
    public void run()
    //some codes
    /*HERE I WANT TO WRITE A CODE WHICH WILL BE RUN AS ORDINARILY
    FROM BEGINING TO THE END WITOUT ANY INTERRUPT*/
    //some codes
    Please help, if you can.
    Thanks in advance
    Tamer

    You can't write a block of uninterruptable code in Java.

  • Run method in Thread subclass

    run method of Base calss is executing when I run this code. If I remove Base.run() it Test1.run() is getting executed. can anybody explain why.?
    class Base extends Thread{
    public native String getTime();
         Base(Runnable r)
              super(r);
         public void run()
              System.err.println("In Base");
    public class Test1 implements Runnable {
    boolean bStop;
    public static void main(String argv[]){
         Test1 m = new Test1();
         m.go();
    public void go(){
         Base ts = new Base(this);
         ts.start();
    public void run(){
              System.out.println(" in Test1");
    }

    What you have done is very odd, and wrong. Why do you have a subclass to thread that overrides the run method?
    This is what the default implementation for the run method in the Thread class looks like:
        public void run() {
            if (target != null) {
                target.run();
        }Where target is the runnable that you passed into the constructor. Your implementation of run does not invoke that runnable.
    Kaj

  • Thread's run method

    I cannot unserstand why the output of this program is:
    axa axa
    class A extends Thread
    public void run()
    System.out.print("axa ");
    public class Main
    public static void main(String[] args) throws Exception
    Thread t = new Thread(new A());
    t.run();
    t.start();

    Guestios wrote:
    Why the
    t.run();
    calls the run() method of the Class A?
    t is just an instance of class ThreadThe implementation of the run() method in the Thread class looks like this:
    public void run() {
         if (target != null) {
             target.run();
    }The 'target' variable is the Runnable you passed to the Thread in the constructor, which was an instance of A, so it's run() method was called.
    Jim S.

  • How to get value from Thread Run Method

    I want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that it seems that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get Inside the run method::: But I get only Inside */
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";

    I think this is what you're looking for. I hold up main(), waiting for the results to be concatenated to the String.
    public class sampsynch
        class SampleThread extends Thread
         String x = "Inside";
         public void run() {
             x+="the run method";
             synchronized(this) {
              notify();
        public static void main(String[] args) throws InterruptedException {
         SampleThread t = new sampsynch().new SampleThread();
         t.start();
         synchronized(t) {
             t.wait();
         System.out.println(t.x);
    }

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • When we create JDialog inside Thread's run() method it is creating problem

    I have application that has feature that mainframe will be locked after three minutes and the time when it is locked it will show other locked dialog.
    Now my problem is given below:
    I have created one Dialog inside Threads run() method and this thread will execute when mainframe is locked.So what is happening is when mainframe is locked internally Thread is doing its job (its job is to display one dialog) and it is displaying dialog but mainframe is locked and still it is showing that dialog.This should not happen in our application when mainframe is locked nothing should come outside.
    simple code sample is given below:
    SwingUtilities.invokeLater(new Runnable()
    JDailog dlg = new JDialog();
    dlg.pack();
    dlg.show();
    Now when my applications mainframe is locked and thread is doing its job when mainframe is locked and it will show one dialog when its run() method will execute and it showing dialog even though mainframe is locked.This is major issue for me.please help me.
    sample code may contain compile errror but this only to give understanding what i am doing actually i cant show my original code.
    But show me some work around for this problem.Why dialog is coming outside when mainframe is locked?
    Please help me.I cant use delay inside run() method because of performance.
    Is there any way to control this behaviour?

    public class BackGroundThread extends javax.swing.JFrame implements BackgroundTaskInf {
        boolean isMainWindowActive = false;
        /** Creates new form BackGroundThread */
        public BackGroundThread() {
            initComponents();
            new DBBackgroudProcess(this).start();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jDialog1 = new javax.swing.JDialog();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jLabel1.setText("JOB DONE");
            javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
            jDialog1.getContentPane().setLayout(jDialog1Layout);
            jDialog1Layout.setHorizontalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addGap(95, 95, 95)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(240, Short.MAX_VALUE))
            jDialog1Layout.setVerticalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(jLabel1)
                    .addContainerGap(22, Short.MAX_VALUE))
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jLabel2.setText("Background work in progess");
            jButton1.setText("unlock");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(56, 56, 56)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(126, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(263, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(74, 74, 74))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(40, 40, 40)
                    .addComponent(jLabel2)
                    .addGap(37, 37, 37)
                    .addComponent(jButton1)
                    .addContainerGap(43, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            isMainWindowActive = true;
            backgroundTaskFinished();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new BackGroundThread().setVisible(true);
        public void backgroundTaskFinished(){
            if(isMainWindowActive) {
                jDialog1.setSize(200,200);
                jDialog1.setVisible(true);
                jLabel2.setText("Task is finished");
        // Variables declaration - do not modify                    
        private javax.swing.JButton jButton1;
        private javax.swing.JDialog jDialog1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        // End of variables declaration                  
    class DBBackgroudProcess extends Thread {
        BackgroundTaskInf infObj;
        public DBBackgroudProcess(BackgroundTaskInf infObj){
            this.infObj = infObj;
        public void run(){
            try{
                // here you can do your backgroudn task
                System.out.println("In BackGroud task");
                Thread.sleep(1000);
                System.out.println("task completed");
                infObj.backgroundTaskFinished();
            }catch(Exception e){
                e.printStackTrace();
    interface BackgroundTaskInf{
        public void backgroundTaskFinished();
    }

  • Pass parameters via POST in WDPortalNavigation.navigateAbsolute method

    Hi,
    how can i pass parameters via POST method from WD Application using WDPortalNavigation.navigateAbsolute method
    Should i pass the parameters as part of the NavigationTarget URL or they should be passed via different parameter?
    Thanks,
    Yuly Roberman

    What is the procedure to pass parameters via POST using WebDynpro ?
    I am required to pass XML Data via POST.
    I have gone through the following :
    a) http://help.sap.com/saphelp_nw04/helpdata/en/9e/a073001903c9419592b14c2aa63669/content.htm
    b) Inter Navigation Application in Web Dynpro
    However, I could not find any reference to do the same via POST.
    Can anyone throw light on the same ?
    Best Regards,
    Subramanian V.

  • How run method is called in a thread

    Hello,
    If I call start method of a thread, then I want to know if run method is automatically called or not.
    Thank you

    A tutorial on threads would doubtlessly contain much of the information you're after. There might be something in the Java Tutorial that's worth looking at.
    Have you tried it to find out what the behaviour is? It's really not very surprising...
    In summary, though:
    The run method of a Thread is called when the Thread is started. You can confirm this by overriding the run method if you want:
    Thread myThread = new Thread() {
      public void run() {
        System.out.println("WOO HOO - Run!!");
    System.out.println("Starting thread");
    myThread.start();
    System.out.println("Thread started");Hope this helps.

Maybe you are looking for

  • Editing AIM profile with iChat?

    This is kind of a silly question, but how do you go about editing your AIM profile through iChat? I've done it a couple times before but I really cannot remember what I clicked on at all since the last time I edited it.

  • Filereader only reads when launched from terminal

    My program consists of a JDialog which is launched from a JApplet. Part of my code requires that an input string be checked against a "dictionary" to see if it is a valid word. The dictionary consists of several word lists, organized by length, in a

  • Need Explanation about code ABAP

    Hi, what does mean this code : *if not SOURCE_ENTETE-MONAT is initial. *BBKPF-MONAT = SOURCE_ENTETE-MONAT.   *endif.                                 i find it in LSMW (step number 5) what does mean exactly initial i want to integrate some FI document

  • JSP Compiler

              Originally I post it to weblogic.developer.interst. But I guess this may be a better space to post the JSP related question. Sorry for the double post           Hi, there,           I tried to use the weblogic.jspc to compile my JSP files f

  • Need help with logo concepts?

    Okay, so you have a good idea, but only some rough sketches or scans of your doodles? Post them here so people can pick them up and work on them. If you have a good design that works for you, but are unable to create all the variations (negative, bla