Thread Concept

Hi, one thing lacking for me is one concept of threads. For example, say i have a customer class that has methods to deletecustomer, addcustomer, editcustomer etc.
I make this runnable.
Then say for instance, i have 3 users. they all want to work on three different customers at the same time.
So
user 1 wants to delete a customer
user 2 wants to add a customer
user 3 wants to edit a customer.
Making a new thread for these is fine. However, one concept i don't understand is what to write in the run method??
I can't type addcustomer, deletecustomer or editcustomer, as these may not always be needed. Can someone help me to understand this please?

Daniel_Redfern wrote:
This is what he wanted....
+"I can't type addcustomer, deletecustomer or editcustomer, as these *may not always be needed*. Can someone help me to understand this please? "+
So you have to bring in the idea that you have to somehow segregate the privileges to a specific user. What I have expressed is a good starting point that brings simple high-level thoughts with no added complexity other than whats required. I haven't stewed him down the route that it has to be some super-duper design. Please if you have any other suggestions on his primary issues we would love to listen. If not, keep you're negitive views to yourself if people are brain-storming
DanielOne more try:
The OP started by writing this:
Hi, one thing lacking for me is one concept of threads. For example, say i have a customer class that has methods to deletecustomer, addcustomer, editcustomer etc.
I make this runnable.Daniel, you're grabbing the wrong end of the stick. The OP has this:
class Customer implements Runnable {
    void deletecustomer() {...}
    void addcustomer() {...}
    void editcustomer () {...}
    @Override public void run() {
        deletecustomer ? addcustomer ? editcustomer ?
}He's confused. He's stuck DAO methods in a business object and then tried to turn it into a task by making it Runnable. I claim it's got nothing to do with user privileges and that will just confuse the OP further.
What the OP really needs to do is step back and describe his problem, not his purported solution.

Similar Messages

  • Need help with the threads concept in java

    i need a good explanation for the threads concept in java.Explanation with an example would be better.

    JosAH wrote:
    BIJ001 wrote:
    Java still can't process them in real time because of its garbage collector.So real-time java is not conceivable \qu.e.d
    http://java.sun.com/javase/technologies/realtime/index.jsp
    http://jcp.org/en/jsr/detail?id=282
    Is that implementation ready yet? The first link talks about 'more real time'; that garbage collector really is a burden when it comes to the real ticks ...
    kind regards,
    JosSpoon!

  • Threading concepts used in servlet programming

    Hello Everybody,
    I have rquirement like .. three servlets are there in my application..by using threading concept only one servlet should get chance ..reaming two are in lock mode till first servlet finishes.
    Any body having idea on this requirement plz help me..If any body having examples related to this ..plz post here.
    Thanks In advance.
    regards,
    Anil.

    I have rquirement like .. three servlets are there in my application..by using threading concept only one servlet should get chance ..reaming two are in lock mode till first servlet finishes.That is an unreasonable requirement, and will end up breaking your web-app the first time it gets accessed by more than one user (ie, you won't see the problem during development, probably not during QA, then you'll get a call as soon as it hits production).
    Why do you think you need this requirement?
    Are the servlets supposed to be executed in a particular order? That can be handled via coding.
    Do they make use of a shared resource? That can be handled by controlling access to the resource. I will note that most shared resources do not need long-term atomicity, and databases already provide it.

  • How to use Threading Concept in oracle

    Hi all,
    I am having requirement such that i have to execute a function after insert of data in one table.due to performance issues i have to execute this function using java pooling.if anybody having idea regarding this one please share.
    I have tried by using simple javaThreading but it is not working.
    Regards,
    Ramesh.

    public static void main (String args[] ) throws Exception {
    log("main thread is: " + Thread.currentThread());
    TaskProcessor taskProcessor[] = new TaskProcessor[5];
    Thread threads[] = new Thread[taskProcessor.length];
    for (int i=0; i<taskProcessor.length; i++) {
    taskProcessor[i] = new TaskProcessor(i);
    threads[i] = new Thread(taskProcessor);
    threads[i].start();
    for (int i=0; i<taskProcessor.length; i++) {
    if (threads[i].isAlive()) {
    threads[i].join();
    * Thread to run many concurrent connections
    private static class TaskProcessor implements Runnable {
    private int number = 0;
    public TaskProcessor(int number) {
    this.number = number;
    public void run() {
    try {
    log("Thread started: " + Thread.currentThread());
    // Get a connection
    Connection conn = ConnectionFactory.getConnection();
    // Sleep and yield so that other threads can run
    Thread.yield();
    //Thread.sleep(1000);
    Thread.yield();
    Connection conn1 =ConnectionFactory.getConnection();
    log("Thread " + Thread.currentThread() + ": First Con: " + conn);
    log("Thread " + Thread.currentThread() + ": Second Con: " + conn1);
    if (conn1 != conn)
    throw new Exception("Connections dont match: " + conn + ": " + conn1);
    log("Thread " + Thread.currentThread() + " over");
    } catch (Exception e) {
    System.out.println("Exception"+e);
    private String getLeastLoadedPool() {
    if (lastNodePoolUsed == null) {
    lastNodePoolUsed = "1";
    return "1";
    if (lastNodePoolUsed.equals("1")) {
    lastNodePoolUsed = "2";
    return "2";
    else {
    lastNodePoolUsed = "1";
    return "1";
    // in connection factory get connection factory
    public synchronized static Connection getConnection() throws Exception {
    if (singletonFactory == null)
    singletonFactory = new ConnectionFactory();
    String poolId = (String) nodePoolTracker.get();
    if (poolId == null) {
    // one and store it in the thread
    poolId = singletonFactory.getLeastLoadedPool();
    nodePoolTracker.set(poolId);
    log("No Pool Associated:" + Thread.currentThread() + ", adding: " + poolId);
    return singletonFactory.getConnection(poolId);
    else {
    log("Pool Associated:" + Thread.currentThread() + ", " + poolId);
    return singletonFactory.getConnection(poolId);
    after creating this class by using lodajava i have loaded in oracle.
    Regrads,
    Ramesh

  • MUlti-threading concept

    Hi All,
    Want to know how we can multi-thread a program for a particular PLSQL code in Oracle EBS for which the child thread doesn't consume any thread in the front-end even though it executes with user-specified threads?

    Hi;
    Please review below notes which could gives you some idea:
    How Does iPayment Use Multi Threading? [ID 983478.1]
    http://orabiz.blogspot.com/2010/06/ebs-plsql-multithreading-example.html
    Can I have multi-thread program in EBS
    Regard
    Helios

  • Establishment of XA "Thread of Control" in a Tuxedo application

    Hello there,
    I am assigned the task of developing an XA compliant resource manager so that a client can use the C interface to our JMS messaging system from a Tuxedo application and have the application's transactions managed by it. The query I have here is abbout establishing the "thread of control" in a Tuxedo context. I'll set out my understanding and the particular queries that I have in the hope that you can confirm whether my understanding is correct and maybe point me in the right direction.
    The XA Specification clearly sets out the requirements for
    successful distributed transaction processing, and the important roles within this for the three participants: the application programme (AP), the resource manager (RM) and the transaction manager (TM). The key concept in XA is the Thread of Control as described in section 2.2.8 of
    the specification. Here is the paragraph describing the pivotal role that identification of thread of control has in transaction coordination:
    <quot>The thread concept is central to the TM's coordination on RMs. APs call RMs to request work
    while TMs call RMs to delineate transaction branches. The way the RM knows that a given work request pertains to a given branch is that the AP and the TM both call it from the same thread of control. For example, an AP thread calls the TM to declare the start of a global
    transaction. The TM records this fact and informs RMs. After the AP regains control it uses the native interface of one or more RMs to do work. The RM receives the calls from the AP and TM in the same thread of control.
    Certain XA routines, therefore, must be called from a particular thread.</quot>
    In developing a RM the key question is what should be used to identify thread of control so that work can be properly assigned to the correct transaction or more specifically XID. The obvious choice here is the thread identifier itself (such as would be returned by
    PRThread* PR_GetCurrentThread(void) when using the Netscape Portable Runtime library).
    As long as AP, RM and TM are all in one process this is not a difficult problem, however many threads may
    be created. It will also work for in our messaging system in the case where branches of the same transaction are executed in separate processes of this type. This is because "transaction assembly" occurs on the "server" when JMS messages are received there. A Message is assigned to a transaction on an individual basis. This also gives us the flexibility to implement various connection pooling mechanisms or use a single connection to transfer messages
    for many different transactions along with messages not participating in an XA transaction at all.
    However, Tuxedo presents a challenge as there cannot be a single thread in this sense as the participants are distributed across several processes. These processes are respectively, client; server and RM; TMS. There are at least two TMS to avoid blocking problems and potentially very many server-RMs. Given this situation how then is it possible for the RM to match up units of work requested by various services with the XIDs that it has been informed of by the TMS? One assumes that a different thread will run in the server/RM process for:
    a) TMS to indicate to RM that a transaction has started, ended, etc., one distinct thread for each of these calls.
    b) service execution, one distinct thread for each call, where there may be many of these making up
    the work of one transaction
    It is obviously preferable from our point of view that our RM should not have to use Tuxedo specific code, but if this is unavoidable then we shall have to live with it.
    BTW in case it is relevant I'm assuming that the RM will not use dynamic registration.
    Thanks for any help,
    Gillian Horne

    Gillian,
    When Tuxedo issues an xa_start() call, the matching xa_end() call will
    always be executed in the same thread of the same process.
    If another xa_start() is executed at a later point for the same transaction,
    that call could be made in a different process, in a different thread of the
    same process, or in the same thread of the same process.
    Tuxedo will call xa_end() with the TMSUSPEND|TMMIGRATE flag pair only for
    certain CORBA transactions. If your application does not use CORBA, then it
    would be acceptable to develop an RM with the TMNOMIGRATE flag set in the RM
    switch. Tuxedo does not use asynchronous XA operations, so you do not ened
    to develop an RM with the TMUSEASYNC flag set.
    The xa_prepare() call for a particular transaction branch can be made in
    different process or thread from the xa_commit() or xa_rollback() call that
    follows it.
    Except in the case of transactions started with the Tuxedo AUTOTRAN feature,
    the xa_prepare() and xa_commit() calls for a particular transaction branch
    will almost always be made in different processes from the processes that
    performed xa_start()/xa_end() calls for that transaction branch.
    There shouldn't be any need to write special RM code for Tuxedo. Popular
    RMs such as Oracle, Informix, DB2, MQ Series, and others have all been able
    to work with Tuxedo, with the former Top End product, with Encina, and with
    other transaction monitors.
    I hope this information is of help in implementing your RM.
    Ed
    <Gillian Horne> wrote in message news:[email protected]...
    Hello there,
    I am assigned the task of developing an XA compliant resource manager so
    that a client can use the C interface to our JMS messaging system from a
    Tuxedo application and have the application's transactions managed by it.
    The query I have here is abbout establishing the "thread of control" in a
    Tuxedo context. I'll set out my understanding and the particular queries
    that I have in the hope that you can confirm whether my understanding is
    correct and maybe point me in the right direction.
    The XA Specification clearly sets out the requirements for
    successful distributed transaction processing, and the important roles
    within this for the three participants: the application programme (AP), the
    resource manager (RM) and the transaction manager (TM). The key concept in
    XA is the Thread of Control as described in section 2.2.8 of
    the specification. Here is the paragraph describing the pivotal role that
    identification of thread of control has in transaction coordination:
    <quot>The thread concept is central to the TM's coordination on RMs. APs
    call RMs to request work
    while TMs call RMs to delineate transaction branches. The way the RM knows
    that a given work request pertains to a given branch is that the AP and the
    TM both call it from the same thread of control. For example, an AP
    thread calls the TM to declare the start of a global
    transaction. The TM records this fact and informs RMs. After the AP regains
    control it uses the native interface of one or more RMs to do work. The RM
    receives the calls from the AP and TM in the same thread of control.
    Certain XA routines, therefore, must be called from a particular
    thread.</quot>
    In developing a RM the key question is what should be used to identify
    thread of control so that work can be properly assigned to the correct
    transaction or more specifically XID. The obvious choice here is the thread
    identifier itself (such as would be returned by
    PRThread* PR_GetCurrentThread(void) when using the Netscape Portable Runtime
    library).
    As long as AP, RM and TM are all in one process this is not a difficult
    problem, however many threads may
    be created. It will also work for in our messaging system in the case where
    branches of the same transaction are executed in separate processes of this
    type. This is because "transaction assembly" occurs on the "server" when JMS
    messages are received there. A Message is assigned to a transaction on an
    individual basis. This also gives us the flexibility to implement various
    connection pooling mechanisms or use a single connection to transfer
    messages
    for many different transactions along with messages not participating in an
    XA transaction at all.
    However, Tuxedo presents a challenge as there cannot be a single thread in
    this sense as the participants are distributed across several processes.
    These processes are respectively, client; server and RM; TMS. There are at
    least two TMS to avoid blocking problems and potentially very many
    server-RMs. Given this situation how then is it possible for the RM to match
    up units of work requested by various services with the XIDs that it has
    been informed of by the TMS? One assumes that a different thread will run in
    the server/RM process for:
    a) TMS to indicate to RM that a transaction has started, ended, etc., one
    distinct thread for each of these calls.
    b) service execution, one distinct thread for each call, where there may be
    many of these making up
    the work of one transaction
    It is obviously preferable from our point of view that our RM should not
    have to use Tuxedo specific code, but if this is unavoidable then we shall
    have to live with it.
    BTW in case it is relevant I'm assuming that the RM will not use dynamic
    registration.
    Thanks for any help,
    Gillian Horne

  • Connection Pooling in OCCI Vs Multi-Threading.

    Hi,
    I am working on an application in which I am using OCCI( Oracle C++ Call Interface)  and multi-threading concepts.
    My application is having different clients( Ex: Client-A, Client-B) and I am offering a set of operations( functions that trigger the Stored Procedures of DataBase ) which are common to all the clients.Each Client can send asynchronous requests of any number.So, is there any chance of using single connection( not connection pooling) to the Data Base for all the clients to manage their requests ?
    Note: Multi-threaded requests are also allowed from each client.
    How can I co-relate multithreading and Connection Pooling in OCCI?
    Can I you multi-threading without Connection Pooling? If so how?
    Will the connection pooling is needed if there is no multi threading concept in my application?
    Please help me on this. Very urgent.
    Thanks in Advance..:)

    Connections are resources that the application uses and a fewer connections can be used by multiple threads if the threads are not always busy with the database activity only, and are doing other work too. This sharing (pooling) can be implemented by the application or the application can leverage the connection pooling features offered by OCI/OCCI (recommended).
    Be aware of connections vs sessions and sharing them (refer to :
    OCI Programming Advanced Topics
    OCCIConnectionPool is to pool connections and OCCIStatelessConnectionPool is to pool sessions. Please see the differences in the above link and apply as appropriate.

  • Thread problem in swing application?

    Hi,
    I have a doubt in GridLayout and Threads. I�m doing one small application which is accepting images and Alphabets. Actually, What I�m doing running images and alphabets(combinedly) in frequent intervals. For this I used GridLayout and Thread concept. But I have a problem in paint method. How to call the GridLayout frequently. In GridLayout , I�m putting Images and alphabets. Acutually in paint method , there are only drawString or drawImage or other methods. Is it possible to call my layout. Is so, can anybody help me in this regard. Is there any way to do it . please suggest me.
    Thanks,
    -Balaji
    My code follows:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.applet.Applet;
    import java.util.*;
    import java.io.*;
    public class GridLayEx2 extends Applet implements Runnable {
    private Random r = new Random();
    private Thread imageThread = null;
    GridLayout glt;
    public void init() {
    glt = new GridLayout(3,3);
    setLayout(glt);
    } // end of init method
    public void start(){
    if (imageThread == null) {
    imageThread = new Thread(this, "GridLayEx2");
    imageThread.start();
    } // end of start method
    public void run(){
    Thread myThread = Thread.currentThread();
    while (imageThread == myThread) {
    repaint();
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e){ }
    }// end of run method
    public void paint(Graphics g){
    Font boldFont = new Font("Helvetica", Font.BOLD, 25);
    Font plainDerived =
    boldFont.deriveFont(Font.PLAIN, 25);
    JLabel myLabel[] = new JLabel[9];
    String myUrl = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\duke1.gif";
    myLabel[0] = new JLabel(new ImageIcon(myUrl));
    myLabel[1] = new JLabel("A");
    myLabel[2] = new JLabel("A");
    myLabel[3] = new JLabel("A");
    myLabel[4] = new JLabel("A");
    myLabel[5] = new JLabel("A");
    myLabel[6] = new JLabel("A");
    myLabel[7] = new JLabel("A");
    myLabel[8] = new JLabel("A");
    myLabel[1].setFont(boldFont);
    myLabel[2].setFont(boldFont);
    myLabel[3].setFont(boldFont);
    myLabel[4].setFont(boldFont);
    myLabel[5].setFont(boldFont);
    myLabel[6].setFont(boldFont);
    myLabel[7].setFont(boldFont);
    myLabel[8].setFont(boldFont);
    int values[] = new int[9];
    values = gen_pos_uni_ran_num(0,8);
    for(int i = 0; i < 9; i++)
    add(myLabel[values]);
    } // end of paint method
    public void stop(){
    imageThread = null;
    } // end of stop method
    public int[] gen_pos_uni_ran_num(int min, int max)
    int results[] = new int[Math.abs(max - min) + 1];
    for(int i = 0; i < results.length; ++i)
    results = -1;
    outer_loop:
    for(int i = 0; i < results.length; ++i)
    int random_int = (int)((Math.random() * results.length) + min);
    for(int j = 0; j < results.length; ++j)
    if(results[j] == random_int)
    random_int = (int)((Math.random() * results.length) + min);
    j = -1;
    continue;
    if(j == results.length - 1)
    results = random_int;
    continue outer_loop;
    return results;
    } // generate unique random numbers
    public static void main( String args[])
    Frame GridLayFrame = new Frame ( " Grid Layout Frame ");
    GridLayEx2 gl = new GridLayEx2();
    gl.init();
    GridLayFrame.add(gl);
    GridLayFrame.pack();
    GridLayFrame.setSize(GridLayFrame.getPreferredSize());
    GridLayFrame.show();
    GridLayFrame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    } // end of main method

    hi,
    i got one doubt in the previous application. i want to put labels in the circle manner while changing my label positions. Now it is rectangular type. And also i want to change my background color of JFrame. Please see my code ...
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.util.GregorianCalendar;
    public class GridLayEx6 extends JApplet{ 
       private Random r = new Random(); 
       private ActionListener taskPerformer;
       private javax.swing.Timer timer;  
       private GridLayout glt;  
       private JLabel[] myLabel;     
       GregorianCalendar todayDate = new GregorianCalendar();     
       long fromTime,toTime,elapsedTime;
       public void init() {     
            glt = new GridLayout(3,3);     
          Font boldFont = new Font("Helvetica", Font.BOLD, 25);     
          Font plainDerived = boldFont.deriveFont(Font.PLAIN, 25);     
             myLabel = new JLabel[9];     
             String myUrl = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\MyArrow.jpg";
             String myUrlA = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\MyA.jpg";     
             URL url = null;     
       try{
       myLabel[0] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);     
       myLabel[1] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[2] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[3] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[4] = new JLabel("+", SwingConstants.CENTER);     
       myLabel[5] = new JLabel(new ImageIcon(myUrlA), SwingConstants.CENTER);
       myLabel[6] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[7] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[8] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[2].setVerticalAlignment(SwingConstants.NORTH);     
       myLabel[4].setFont(boldFont);     
       getContentPane().setLayout(glt);     
      } catch( Exception e)
        { System.out.println(" Exception occurs "+e);}
       int delay = 20000; //milliseconds     
       ActionListener taskPerformer = new ActionListener() {     
       public void actionPerformed(ActionEvent evt) {      
                 randomDuke();
       timer = new javax.swing.Timer(delay, taskPerformer);     
       addKeyListener(new KeyAdapter()      {        
          public void keyPressed(KeyEvent e){           
                 GridLayEx6 gl2 = (GridLayEx6)e.getSource();           
                     switch(e.getKeyCode())
                           case(KeyEvent.VK_ENTER): 
                                gl2.randomDuke();                 
                                break;
                       case(KeyEvent.VK_SPACE):              
                            if(gl2.timer.isRunning())                    
                              { gl2.timer.stop();                 
                                    toTime = System.currentTimeMillis();
                                 elapsedTime = toTime - fromTime;
                                 System.out.println("toTime : "+toTime);
                                 System.out.println("elapsedTime : "+elapsedTime);
                                  gl2.timer.start();
                                   gl2.randomDuke();
                               break;
                       case(KeyEvent.VK_KP_RIGHT):case(KeyEvent.VK_KP_UP):              
                       case(KeyEvent.VK_RIGHT):case(KeyEvent.VK_UP):              
                         int delay = gl2.timer.getDelay();
                         if(delay > 0)                    
                            gl2.timer.setDelay(delay - 100);                 
                            break;
                       case(KeyEvent.VK_KP_LEFT):case(KeyEvent.VK_KP_DOWN):              
                       case(KeyEvent.VK_LEFT):case(KeyEvent.VK_DOWN):
                            int delay = gl2.timer.getDelay();                  
                            if(delay < 10000)                    
                                 gl2.timer.setDelay(delay + 100);                  
                                 break;
                       //timer.start();  
             } // end of init method  
             public void start()   {     
                  timer.start();     
                    while(!isFocusOwner())        
                            requestFocus(); 
             } // end of start method     
             public void stop(){    
                  timer.stop();
            } // end of stop method     
             /** To make sure we have focus in application *  
             * mode if JFrame loses focus control          *  
             * - non standard usage of paintComponent      */    
             public void paintComponent(Graphics g)   {
                  while(!isFocusOwner())        
                       requestFocus();  
            public void randomDuke()   {     
                  fromTime = System.currentTimeMillis();
                  System.out.println("fromtime : "+fromTime);     
                  getContentPane().removeAll();     
                  int[] values = new int[9];     
                  int temp;
                  values = gen_pos_uni_ran_num(0,8);     
                  for ( int i=0; i<=8;i++)
                          if ( values[i] == 4)
                                 temp = 4;
                                 values[i] = values[4];
                                 values[4] = temp;
                  for(int q = 0; q < 9; q++)   
                        getContentPane().add(myLabel[values[q]]);    
                       myLabel[0].revalidate();
                       myLabel[1].revalidate();
                       myLabel[2].revalidate();
                       myLabel[3].revalidate();
                       myLabel[5].revalidate();
                       myLabel[6].revalidate();
                       myLabel[7].revalidate();
                       myLabel[8].revalidate();
                    } // end of randomDuke method  
              public int[] gen_pos_uni_ran_num(int min, int max)   {     
                  int results[] = new int[Math.abs(max - min) + 1];     
                  for(int q = 0; q < results.length; ++q) 
                       results[q] = -1;     
                  outer_loop:     
                  for(int q = 0; q < results.length; ++q)  
                       int random_int = (int)((Math.random() * results.length) + min);        
                    for(int j = 0; j < results.length; ++j)       
                        if(results[j] == random_int)            {              
                            random_int = (int)((Math.random() * results.length) + min);              
                            j = -1;
                      continue;           
                     if(j == results.length - 1)
                          results[q] = random_int;              
                          continue outer_loop;
                  return results;  
                  } // generate unique random numbers  
                  public static void main( String args[])
                        JFrame GridLayFrame = new JFrame ( " Grid Layout Frame ");     
                       GridLayFrame.setSize(500,500);     
                       GridLayEx6 gl = new GridLayEx6();     
                       gl.init();     
                       GridLayFrame.getContentPane().add(gl);     
                       //GridLayFrame.setBackgroundColor(Color.white);
                       GridLayFrame.setVisible(true);
                       gl.start();     
                       GridLayFrame.addWindowListener(new WindowAdapter()      
                         public void windowClosing(WindowEvent e)         
                        System.exit(0);         }      });  
                  } // end of main method
                  }

  • Calling thread.start() more than once concurrently

    Hi, I got a simple doubt that may feel awkward or absurd to people who are well versed in the java threading concepts. I just thought of it and as I couldn't get an easy answer I am posting this.
    Consider a class that implements the runnable interface. The run() method of the class is implemented with just a System.out.println(). If I make an instance of this class, say 't' in the main method and calling t.start() susequently twice or thrice; an illegal ThreadStateException will be thrown. The code snippet is as follows:
    ThreadTest t = new ThreadTest();
    t.start();
    t.start();
    It is understood that state of the thread object is changed to run state and so, if it is again started, it must be thrown. So if I put a Thread.sleep() inbetween these two subsequent calls assuming that the main method thread will be sleeping. So there is sufficient time for the first thread to terminate and then only the second will start - still the same exception is being thrown. I tried putting the synchronized qualifier for run too, still no effect - the same only happening. Why the java thread object is made in such a way that once the thread changes it state from Runnable to Running and then finally to dead state, it can be restated back to Runnable state, such that the start() method can be called again. Is it possible or not? Please post your comments.

    As ejp says you can't start a thread more than once - even if it has already terminated after the first start.
    By making threads a one-shot it simplifies reasoning about them: you don't have to wonder whether a second start() will work or not, depending on whether the thread has completed its first "incarnation". It also makes it easier to ensure thread resources are reclaimed. It also avoids semantic issues like whether anything about the thread is "carried over" across incarnations.
    This might seem a limitation but there are many ways around it - simply don't let the thread terminate. Whatever control structure you would enforce by re-starting the thread can be emulated without letting the thread terminate in between "executions".

  • Creating a thread object in ABAP

    Hi,
    Is it possible to create a threa in ABAP function modules or in ABAP objects or in both?
    For example do the following in ABAP code:
    while(true){
    if(someCheck)
    else
    terminate thread
    }thread sleep(1 second)
    regards
    Baran

    There is nothing like threads concept in ABAP.
    But parallel processing can be done like this example:
      DO V_LINES TIMES.
        V_TASK_COUNT = SY-INDEX.
        CONCATENATE 'TASK_' V_TASK_COUNT INTO V_TASK_NAME.
        READ TABLE IT_ARBPL INTO WA_ARBPL INDEX SY-INDEX.
        P_ARBPL = WA_ARBPL-ARBPL.
        REFRESH IT_ORDERS.
        CALL FUNCTION 'ZPP_PARALLEL_PROCESS'
          STARTING NEW TASK V_TASK_NAME
          PERFORMING COLLECT_DATA ON END OF TASK
          EXPORTING
            E_ARBPL   = P_ARBPL
            E_WERKS   = P_WERKS
            E_ZPPUOM  = 'H'
            E_DATES   = IT_DATES
          TABLES
            ET_ORDERS = IT_ORDERS.
        IF SY-SUBRC EQ 0.
          ADD 1 TO V_WC_COUNT.
        ENDIF.
      ENDDO.
      WAIT UNTIL V_WC_COUNT = V_NUMBER_OF_WCS.
    Regards,
    Ravi

  • How to use a thread as daemon thread

    In multithreading i have undergone through daemon thread concepts and its mentioned as low priority thread which runs in the background of garbage collection.
    My query is how to make the thread daemon thread r we going to use thread priorities here.
    Can anyone demonstrate with an example reg this. I will be very much thankful to them.

    In general, threads that run application code are not daemon threads, and threads that run system code are daemon threads,so the daemon attribute is queried using the isDaemon() method; it is set using the setDaemon() method.....

  • Why Threading is not allowed in EJB?

    Hello,
    I learnt that threading concepts is not allowed/used in EJB.
    can u please post your view, regarding the above question.
    Thanks

    Good mourning...
    EJB isn't used to web applications only, and also exist the Entity beans, the persistent beans and Message Driven Beans. EJB is a enterprise component that is deployed in Application Server. The AS harness the EJB instances amount. This amount is defined in ejb-jar.xml file. And, really, the EJB is thread-safety, thus only a client is connected in the specific time. For more and better information, read the Mastering EJB book, it's free download in theserverside.com, and this sections:
    - Several Entity Bean Instances May Represent the Same Underlying Data (pag. 114);
    - Entity Bean Instances Can Be Pooled (p�g 116).
    treat this specific issue.
    bye!

  • Threading problems

    Currently I have written a server and client pair application using java socket. In the server side, I am using threading concept to create multiple connection. The multiple connections are to cater for the needs of receiving file, chat and so forth. Before that, I've written a password program which only enables user with valid username and password to proceed. Now, I want to link the password program to the server program. My way of doing that was create a if/else method in the main function. If the password class return a true value, then the server class will be called. However, the server window can pop up but the thread is not running. By right, when I start up my server program, the thread for multiple connections will start running. Can anybody knows about this give me some suggestion to solve the problems?
    For both the programs, I'm using JBuilder to design the user interface.

    Instead of authenticating the user in the main method, it sounds like you need to do it in each thread's run method. But it's hard to say without knowing more about your design.

  • Thread- PostUIMessage throws com_error Exceptions

    We have developed a TestStand (4.2) OI including a tracelogger function. Code moduls (dll's coded in C++) used in sequences can send trace messages to the OI using the PostUIMessage function (see following code):
      try
        // Get the thread that is
    executing from the Sequence Context  
        thread =
    seqContext->GetThread();
        thread->PostUIMessage(
    static_cast<enum
    UIMessageCodes>(UIMsg_UserMessageBase+4)
    ,Level
                              ,_bstr_t(Msg)
    ,TRUE);
      catch( _com_error &com_error ) /* TestStand API only
    throws this kind of exception */
    It happens that every 10ms a message is send. In general this works well both when running the sequence in the sequence editor and in our OI. But after a time spawn of about 10 min to a few hours (depends on the frequency of the messages) the PostUIMessage throws a com_error Exception.
    Remark: The code is declared as critical section to ensure it works in multi threaded environments too.
    Does someone has an idea what might be the reason for these exceptions and how to avoid them?
    Thanks in advance
    Peter
    Solved!
    Go to Solution.

    Mr.Doug,
                  Thanks for the Valuable reply. I am sorry for my late reply.
    I have applied the thread priorities to all threads and there is no change in CPU time ( No effect using multi threading concept). I would like to know in detail Mr.Doug..
    My Problem :
                       1) Collecting data (which is a flaw location from plate) with the help of ultrasonic waves and its real time data, I am displaying the flaw location which is collected (using PCL 1751 cards) in the Graphical format. Here i am not getting the actual position of the flaw. Due to the time delay.
    Solution implemented :
                       1) Implemeted multi thread concept but still facing the same issues.
    Example:
    Actual flaw position say : 120 MM (from plate)
    First time when i execute my application it shows : 110 MM
    Next time when i execute it shows as                    : 113 MM
    Like this it varying every time.
    Could you please help me out to sort this issue.
    Thanks and Expecting the Solution....

  • Sending emails using threads

    i have a situation where i need to send mails using threads concept can any one give an idea to how to proceed coz iam new to threads concept
    Thanks in advance

    i have the code to send mails but i need to send bulk mails around 5000 at a time i am using weblogic 8.1 server with jdk 1.4
    the main issue is mails are sent multiple times to the reciepients while using the code, the reciepients are complaining about this.
    for your reference iam posting the code again
    Message message = new MimeMessage(InvitationSender.session);
    String addrFrom = invitation.getFromEmail();
    String fromName = invitation.getFromName();
    Address fromAddress = new InternetAddress(addrFrom);
    message.setFrom(fromAddress);
    message.setSubject(invitation.getInvitationSubject());
    message.setContent(gMessage.getMessageBody(), invitation.getContentType());
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(eAddr.getAddress(), eAddr.getName()));
    Transport tr = session.getTransport("smtp");
    String host = System.getProperty("host");
    String username = System.getProperty("username");
    String password = System.getProperty("password");
    tr.connect(host, username, password);
    message.saveChanges();
    tr.sendMessage(message, message.getAllRecipients());
    tr.close();
    i have posted the code of the send mail method and all said the code doesnt have any problem and some one suggested me to use threads thats why i am seeking some thoughts on how to do that
    thanks in advance

Maybe you are looking for

  • New Version of BT Yahoo Classic Mail Major problem

    I have tried to use the new version of BT Yahoo Mail & have encountered a major problem. When I select any area of the new mail page I get a message that says "E Mail out of Memory Line 1" My computer then locks up totally, & I have to turn of with t

  • Problem with READ statement

    hi, my data declarations and code is as follows: types:ty_bapi_return     LIKE  bapiret2. data: t_return            TYPE  STANDARD TABLE OF ty_bapi_return,       wa_return           TYPE                    ty_bapi_return. CALL FUNCTION 'BAPI_ACC_DOCU

  • How can you increase/change the font size using window.print

    We don't use BI/XML Publisher. I have a button with an URL Redirect to print. javascript:window.print(); How can I give the user the option to print with a different font or larger size or optionally to set it the same for everyone? thanks John

  • Image Quality of Nikon D800 in CS5

    Hi, I initially had the issue with Photoshop CS5 not being able to recognize RAW files from my Nikon D800. I managed to sort-it-out by installing the RAW Plug in 6.7 hense now CS5 opens up the RAW files from D800. However, now I'm faced with the diff

  • Gps doesn't work without a sim card

    Does anyone know why GPS on my N900 doesn't work unless my sim card is inserted? GPS seems to work on all my other Nokias without sim card (although obviusly it takes much much longer to locate me) but on the N900 I don't seem to get a gps fix at all