What's wrong to put Thread.sleep in a session bean?

i am working on a trading platform and i think there is a design flaw. The part i am working on is the Order Management module. When an order value object is published to a JMS topic and picked up by a MDB. The MDB, in turn, calls a session bean (could be stateless, I didn't check), OrderEngineBean. After this bean saves the order vo into database and broadcast the message to all involved parties, it suspends for 12 sec, using Thread.sleep, so other parities might have a chance to update the vo. If no update occurs, the order is considered expired and abandoned.
It looks awkward to me to use a Thread.sleep in a session, but I haven't come out with a better idea to deal with the scenario like above.
Anyone can help me out?
Thanks a lot!
Sway

Setting the property "max-beans-in-free-pool" is not the answer to this issue. By setting this property to 1, the container merely instantiates and keeps one instance of the bean in the free pool at the "start" of the app server. But if the container comes across more than one requests for the same EJB simultaneoulsy, then it will create new instances at that time to handle the requests simultaneously.
You are seeing intermixed log messages between two threads because these messages are being logged from two different instances of the EJB and NOT the same instance of the EJB. The container does synchronizes the calls on "a method" on "a instance". So what you are seeing are the messages coming from "a method" on "two different instances" of the same EJB.
You can refer to the EJB 2.0 specification section 6.11.6 Non-reentrant instances for details about simultaneous access to the same session object.

Similar Messages

  • What is an alternate to Thread.Sleep()?

    What is an alternate to thread.sleep? The reason being, my action listener won't let me throw exceptions so I need an alternative to thread.sleep, anything?

    watwatacrazy wrote:
    What is an alternate to thread.sleep? The reason being, my action listener won't let me throw exceptions so I need an alternative to thread.sleep, anything?I am in no way condoning this idea, because as mentioned it is a very bad idea.
    However. Not lettiing you throw exceptions is not a reason to not do something. All it means is that you need a catch block. You should review the exceptions part of the Java tutorial found here [_Java Tutorial : Exceptions_|http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html]

  • OrionRemoteException: Second thread call to stateful session bean

    What happen for "com.evermind.server.rmi.OrionRemoteException: Second thread call to stateful session bean".
    I am using JSP/Servlet/EJB and OC4J. When user click the JSP page button to fast, sometimes the error will appear, and then the OC4J will stop, I need to restart the OC4J.
    I am using standlone OC4J 9.0.3.0.0
    Thanks in advance,
    Perry

    Have you cached the remote object you obtained for the stateful session beamn and are reusing the same object on subsequent requests from the JSP page? So in effect, you are making a second call to the bean before the first method call completes?
    Without knowing anything about what you are doing or how you app is constructed, you may want to set some form of flag for the user session to indicate whether the bean is in use, which you can check before using the bean in requests. When the bean method call completes, open the gate again. If the bean is in use, return a nice message to the user telling them to hold off for a short while.
    -steve-

  • 1) Second thread call to stateful session bean.

    Hi Friend,
    I read your threads on otn and i compared your problem with us and i analysed that your application and my application is same, So Plese can you help me in some issues.
    Friend, Please help me in these issues, Thanks for this
    We have very big ADF Swing+BC Application and deployed as Stateful Session Bean. in my application there are 500 Application Modules,For each application module i created Stateful session beans and deployed it on OC4J Container but when working on deployed application then i am getting time out error after 15 min of working.
    1). I set that parameter that you mentioned i.e jbo.ejb.txntimeout = 86400,but still it is giving me same error.
    2). Second Issue is of ---ORA-01000: maximum open cursors exceeded
    For this issue i chaged the Database Parameter i.e OpenCurser=2000, but still it is giving me same error,
    is there any parameter on application module required to change so that this error will not come.
    3). When i close the form then application module is not releasing database connection.
    4). (oracle.oc4j.rmi.OracleRemoteException) Second thread call to stateful session bean
    This error is also coming when I am using deployed application for long time i.e more than 15 min for Heavy Transactions

    Hi Suyog,
    How r u?
    We all are fine.
    I alerady tried for the Max Curser Property but it is not helpfull.
    I think again i have to go for closing opened db RS and statements.
    Thanks
    Vijay

  • Spawning thread in the stateful session bean

    I ran into an interesting issue: I am spawning a thread inside
    my stateful session bean's ejbCreate(...) method. The spawned
    thread runs in an infinite loop until some stop signal. The
    thread uses some BMP entity beans to access some data from DB,
    it creates some BMP entity beans as well as creates another
    stateful session bean in each iteration. The application ran
    into a crash. Now I have a couple questions:
    - First, is it an allowed operation to have a stateful session
    bean spawn off threads? Am I violating the specs?
    - Second, is it also allowed to have that thread create another
    bmp entity bean and another stateful session bean? Again, am I
    violating the specs also in here?
    Your responses will be very much appreciated.
    - Simon

    From the EJB 2.0 Spec, Section 24.1.2:
    <quote>
    These networking functions are reserved for the EJB Container.
    Allowing the enterprise bean to use these functions could compromise
    security and decrease the Container’s ability to properly manage the
    runtime environment.
    • The enterprise bean must not attempt to manage threads. The
    enterprise bean must not attempt to start, stop, suspend, or resume
    a thread; or to change a thread’s priority or name. The enter-prise
    bean must not attempt to manage thread groups.
    <quote>
    And, spawning threads in weblogic is highly discouraged in any
    server-side component. An application should not be designed this
    way.
    Bill
    Simon wrote:
    I ran into an interesting issue: I am spawning a thread inside
    my stateful session bean's ejbCreate(...) method. The spawned
    thread runs in an infinite loop until some stop signal. The
    thread uses some BMP entity beans to access some data from DB,
    it creates some BMP entity beans as well as creates another
    stateful session bean in each iteration. The application ran
    into a crash. Now I have a couple questions:
    - First, is it an allowed operation to have a stateful session
    bean spawn off threads? Am I violating the specs?
    - Second, is it also allowed to have that thread create another
    bmp entity bean and another stateful session bean? Again, am I
    violating the specs also in here?
    Your responses will be very much appreciated.
    - Simon

  • What is wrong with my thread condition??

    I have two kinds of threads:
    1) WriterThread is cable of inserting keys with a corresonding object into a database.
    2) ReaderThread which should be able to wait for a specific key is inserted into the database.
    I store the key waited for by a ReaderThread and its id in a HashTable (the database is also a Hashtable).
    If I have 3 ReaderThreads that is waiting (with id 1,2,3) and thread 2 is waiting for "key2", I would only have ReaderThread 2 to wake up when "key2" is inserted by a WriterThread.
    Therefor I have made a condition in the "waitfor" method for the threads that is awakened (its after the first call to wait()). But it only works the first time I insert one of the keys awaited keys. The next time I insert a key all the remaining threads are reactivated!
    public class DataBase extends Hashtable{
        private Vector thread_vector; // The vector that contains all the threads.
        private Hashtable hold = new Hashtable(); // Holds the id and the key the thread is waiting for.
        private int t_id = 0; // The id of the thread that gets updated each time insert is called.
        public DataBase(Vector v){
            thread_vector = v;
        public void findId(Object k){
            int q = ((Integer) k).intValue();
            t_id = q; // Here t_id is set to the very id of the thread that is waiting for the newly inserted key.
        public synchronized void insert(String key, String o){
            if (this.containsKey(key)){
                System.out.println("Database already contains key: \""+ key + "\".");
            else{
                if (hold.containsKey(key)){
                    this.findId(hold.get(key));
                    hold.remove(key); // The key that has been waited for is deleted from the waiting queue array.
                    System.out.println("Key: \"" + key +"\" inserted");
                    this.put(key,o);
                    notifyAll();
                else{
                    this.put(key,o);
                    System.out.println("Key: \"" + key +"\" inserted.");
        public synchronized void delete(String key){
            this.remove(key);
            System.out.println("Key: "+"\"" + key + "\" with its corresponding value is removed from the Database." );
        public synchronized void waitfor(String key, int id){
            Integer thread_id = new Integer(id);
            hold.put(key,thread_id);
            try{
                wait();
            catch(InterruptedException e){}
            // This is where the problem is and where all the awakened threads battle to get inside the monitor!!
            if (Thread.currentThread() == thread_vector.get(t_id)){
                System.out.println("The right thread is awakened");
            else{
                try{
                    System.out.println("Return to wait");
                    wait();
                catch(InterruptedException e){}
    }

    Well, when it checks if the key is in the hold table, if it is then 'notifyAll()' notifies all threads!
    Try this, instead if an int to identify the threads, try using a monitor, that way instead of 'notifyAll()' you could use:
    ((Thread)hold.get(key)).notifyAll()Then only the thread that is registered for that key get's notified.
    and in the waitFor method use:
        public synchronized void waitfor(String key, Object id){
            Integer thread_id = new Integer(id);
            hold.put(key,thread_id);
            try{
                id.wait();
                }

  • Can someone tell me what's wrong with my threading code

    I got some code from a Java book on how to create a simple threading application. This is the exact code from the book but for some reason it gives me an error that non-static variables can not be referenced from static content. How can I reword this to work?
    <CODE>
    package multithread;
    import java.io.*;
    import java.util.*;
    public class MultiThread {
    class CountDownEven extends Thread {
    public void run() {
    for (int i = 6; i > 0; i -= 2) {
    System.out.println(this.getName() + " Count" + i);
    Thread.yield();
    class CountDownOdd extends Thread {
    public void run() {
    for (int i = 5; i > 0; i -= 2) {
    Thread.yield();
    public static void main(String[] args) {
    try {
    CountDownEven count1 = new CountDownEven();
    CountDownOdd count2 = new CountDownOdd();
    count1.start();
    count2.start();
    catch (Exception e)
    </CODE>

    One possible solution:public static void main(String[] args) {
         try {
              MultiThread m = new MultiThread();
              CountDownEven count1 = m.new CountDownEven();
              CountDownOdd count2 = m.new CountDownOdd();
              count1.start();
              count2.start();
         } catch (Exception e) {
    }

  • Second thread call to stateful session bean

    Hi,
    My application runs on 9.0.3 and works fine.
    I am migrating my application from OC4J 9.0.3 to OC4J 9.0.4.
    Anyone knows anything about this error ? I don't understand where is the problem.
    Thanks.
    Bye

    Hello,
    I work with Chris and this is one of the stacktraces we get while running two clients. I say "one of" because sometimes I get another one too, with the description "No Active transaction".
    When there is only a single client, the client program runs OK, but when there are more than one client, one of them aborts with an error.
    The pseudo-code, as Chris said, is:
    1. getSessionContext().getUserTransaction().begin();
    2. Do DB stuff (CMP, BMP etc)
    3. getSessionContext().getUserTransaction().commit();
    Each one theses steps is a remote call.
    I tried to print the status of the transaction before the commit and it normally prints ACTIVE. But suddently after some number of runs (), the status returns NO_TRANSACTION and the program aborts.
    Thank you,
    João.
    This is the stackTrace:
    javax.transaction.RollbackException
         at gov.utrafe.engine.facade.ejb.TransactionFacadeBean.commit(TransactionFacadeBean.java:235)
         at TransactionFacade_StatefulSessionBeanWrapper58.commit(TransactionFacade_StatefulSessionBeanWrapper58.java:270)
         at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:124)
         at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
    Caused by: javax.transaction.RollbackException
         at com.evermind.server.ApplicationServerTransaction.commit(ApplicationServerTransaction.java:676)
         at com.evermind.server.ApplicationServerTransactionManager.commit(ApplicationServerTransactionManager.java:433)
         at gov.utrafe.engine.facade.ejb.TransactionFacadeBean.commit(TransactionFacadeBean.java:226)
         ... 8 more

  • What's s the best automated route from stateless session bean class to EJB?

    Hi,
    I have an application that generates stateless session bean classes.
    For any given stateless session bean class, I would like to build an EJB, moreover, I would like to automate the process as much as possible.
    I'd rather not rely on a full blown third party IDE.
    I reckon could write a set of java classes that could analyse the session bean class and generate the home and remote interface and a basic deployment descriptor.
    That said, I have no doubt that I would be renventing the wheel.
    But I am struggling to find a utility/class of the appropriate granularity in the public domain.
    I am wide open to any feedback on approaches people may have taken and the pros and pitfalls.
    I fully realise my question is quite unspecific, but I really wanted to get some feedback and start a discussion. Since, I am sure there is no 'correct' answer.
    Most kind regards,
    Simon.

    My best advice: surrender to use an IDE.
    You wonder sometimes at how much productivity (read as 'time') could be wasted by doing something that could be done automatically. For a learning experience or a once only exercise is fine but as a routine thing, not worth it.
    Cheers

  • Using Thread.sleep()

    When I put Thread.sleep() in my code, the debugger says I need to catch it. How do I do that?

    But in general, you don't want to just smother exceptions like that. It's okay when you're sleeping (or can be) because often if you're interrupted, you want to just ignore it and move on. However, there's more to handling exceptions than just an empty catch block.
    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

  • What are the advantages stateful session beans takes over than HttpSession

    Hi
    We can use HttpSession to maintain the conversational state with the client.
    Then why we need to go for stateful session beans to maintain conversational state with the client.
    What are advantages we can have while using stateful session beans ratherthan HttpSession????.
    Regards
    Dhinesh kumar R

    I think we can use the magic word in the software development "seperation of concerns" ;-)
    HttpSession is in the Servlet/JSP tier and is mainly used in the presentation logic tier (UI, page flows, navigation etc..)
    where the stateful session bean's concern is to maintain a conversational state in a business logic tier.
    Through this seperation its possible, that the business tier's state is undependant from the HttpSession and you dont create a hardlink that could cause problems later. Imagine having a desktop client accessing your business logic etc. not every client needs to be a web client ;-)
    I hope that the answer helps you understanding the topic :-)
    Brgds,
    Nail

  • I can't turn my laptop on after I put it to sleep. What's wrong with it?

    Hi. What's wrong with my laptop? I put it to sleep then won't turn on anymore.

    First, you can force the Mac to shutdown by pasting in this command in Terminal (in Applications>Utilities). Only paste it in. Don't try to type it.
    sudo shutdown -h now
    Hit return. You will be asked for your admin password. Nothing will appear on the screen when you type it in. This is normal. You will also get a warning about using sudo, which you can ignore. This is safe. After you enter your pword, hit return again.
    Then, boot up again into Verbose Mode by holding down the v key at the startup chime. This will bring you to a screen that shows the boot sequence in text as its loading. It will go by kind of fast, but we're not interested in the bootup process. Next, do a normal shutdown and you may be brought to the same kind of text screen, which will show the shutdown sequence. (I know this works this way in Snow Leopard after booting in Verbose mode; not sure about Tiger, though.) If it hangs, it may show in what part of the shutdown process it's hanging. Have a camera or note paper ready to write down where it's getting stuck.
    One other thing to try is an SMC Reset. Unplug from wall power, leave for ten minutes, then hold in the power button for five seconds. Reconnect to power and startup again.

  • After I click on sleep, my iMac wakes up immediately after, what's wrong?

    I want to make my iMac sleep, I click on SLEEP, it goes in sleep mode for a second and wakes up immediately. I don't touch my mouse nor the keyboard… What's wrong?

    Open System Preferences > Energy Saver
    Click:  Restore Defaults
    Then put your Mac to sleep.

  • My iPod Shuffle (4th Generation) flashes red when I put it in the USB drive. What is wrong and how do I fix it?

    Earlier today, I tried to use my shuffle, but for some reason, not only did it not play music, it gave a tri-tone. When I put it into the USB of my computer, the light flashed red for a moment then stopped. My iPod does not show up on iTunes nor My Computer. Can someone tell me what is wrong and how to fix this?

    Kathleen,
    Start with this Apple support document.
    http://support.apple.com/kb/TS1410
    B-rock

  • What's wrong with my iPhone? I put it on the charger it's says it's charging but nothing happens and when I use it while it's charging it starts to die and stops at 1%

    What's wrong with my iPhone? I put it on the charger it's says it's charging but nothing happens and when I use it while it's charging it starts to die and stops at 1%

    Please help

Maybe you are looking for

  • How to print the data in ALV list  format using an existing layout

    Hi all Iam displaying the output in ALV list format and I saved the layout with some name now my requirement is i have to provide a field to select the layout name with F4 help and if i execute the program it should show the output with that layout f

  • What connects do I need to hook up a 2nd LCD monitor to my p7-1380t HP computer?

    My current monitor is a Samsung Starlight LCD monitor hooked up to my p7--1380t (approx 23 inches).  I want to set up a 2nd monitor which is a DELL LCD (unable to find monitor model #). Can you advise me which ports to use on the back of my computer

  • How to clear the hung calls in CUBE?

    I'm installing a new CUBE as SIP-SIP gateway in Cisco 2921, IOS: 15.1(4)M3. When i tried few test calls, I saw couple of hung calls in it. I tried clearing them manually with the below command but it didn't help. clear call voice causecode identifier

  • Deskjet f2480 - duplex / 2-side printing

    Hello there, i have been trying to get this HP deskjet F2480 to print double sided but it always prints the odd pages but i cannot get it to print the even pages. my previous hp had an onscreen and a button prompt for the reverse side printing. this

  • ThirdParty Subcontracting Process

    Hi Experts, Can you  share the usage and process of thirdparty subcontracting process  step  by step in MM Regards, Udaya. Note : Subject is widely discussed FAQ. Please search forum before posting. Edited by: Jeyakanthan A on Dec 5, 2011 10:22 PM