Spawning multiple threads inside a Servlet

Hi All,
We have a situtation where we need to crawl various sites/databases for information to perform a search. As we all know, the most efficient way is to multithread the application. Since J2EE discourages custom Multithreading, we had to search for alternatives to accomplish this task.
We came across few interesting solutions using JMS/MDB. Other than using these is there a simpler way to accomplish this. Any help is appreciated...
Thanks,
Srini

oc4j/orion is the fastest servlet engine on the planet. Those
guys in Sweden don't let you mess around with the number of
servlet instances available. The message here is that you do not
have to resort to any tricks that other servlet engines use to
make sure your servlet will be available to be served up...it
will.
The only thing that slows it down are lack of memory or lack of
resources (the database isn't replying fast enough). You can
solve these problems by clustering your servers on several
machines.
regards,
the elephantwalker
www.elephantwalker.com

Similar Messages

  • Servlet spawning multiple threads causes server to freeze PC

    I'm attempting to write a servlet which, upon receipt of a particular GET request, spawns a thread to do various work which can then be queried by a different GET request. A third type of GET request stops a specified thread.
    This is working fine, except that I can only seem to have spawned one thread at a time. When I spawn another thread, my entire PC stops responding (even Windows Task Manager becomes so sluggish that I cannot kill the server) , and I have to do a hard reset of my PC. I'm using Sun Java System Application Server. The server logs do not contain any errors. I've tried the NetBeans debugger a bit, and it seems to happen when I call the start() method of the Thread.
    This is my first experience with servlets, as well as my first experience with Sun Java System Application Server. I'm also not a Java expert by any means. I'm sure I'm doing something stupid, but I haven't a clue what.
    I can post my code if necessary, but does anyone have any idea what could be causing the server to stop responding just because a servlet spawns two threads? Should I post my code?
    Sorry if this is a n00b question. Thanks in advance.

    I think you may need to spawn it into HTML frame. Each frame will perform
              and download independently.
              Is it what you need ?
              Siros
              "sam ernie" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              >
              > In our application, the content of the main page is being
              > retrieved from different databases. All the requests originiate from
              > one JSP to different databases to retrieve the info. As the JSP
              > processes each of the request sequentailly, there is considerable delay
              > before the contents are displayed to the user.
              >
              > What I want to acheive is spawn multiple threads and display the content
              > to the user in fractions as each thread returns. For eaxmple, if the
              > user has subscribed to three news servers.. I want to be able to
              > display the news from first server to the user without waiting to
              > recieve response from the other two servers.
              >
              > What is the best approach to follow for such requirements ?? Any
              > thoughts on this would be highly appreciated.
              >
              > Thanks,
              >
              > Sam
              >
              

  • Spawning multiple threads ?

    Hi,
              In our application, the content of the main page is being
              retrieved from different databases. All the requests originiate from
              one JSP to different databases to retrieve the info. As the JSP
              processes each of the request sequentailly, there is considerable delay
              before the contents are displayed to the user.
              What I want to acheive is spawn multiple threads and display the content
              to the user in fractions as each thread returns. For eaxmple, if the
              user has subscribed to three news servers.. I want to be able to
              display the news from first server to the user without waiting to
              recieve response from the other two servers.
              What is the best approach to follow for such requirements ?? Any
              thoughts on this would be highly appreciated.
              Thanks,
              Sam
              

    I think you may need to spawn it into HTML frame. Each frame will perform
              and download independently.
              Is it what you need ?
              Siros
              "sam ernie" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              >
              > In our application, the content of the main page is being
              > retrieved from different databases. All the requests originiate from
              > one JSP to different databases to retrieve the info. As the JSP
              > processes each of the request sequentailly, there is considerable delay
              > before the contents are displayed to the user.
              >
              > What I want to acheive is spawn multiple threads and display the content
              > to the user in fractions as each thread returns. For eaxmple, if the
              > user has subscribed to three news servers.. I want to be able to
              > display the news from first server to the user without waiting to
              > recieve response from the other two servers.
              >
              > What is the best approach to follow for such requirements ?? Any
              > thoughts on this would be highly appreciated.
              >
              > Thanks,
              >
              > Sam
              >
              

  • Where can we tell OC4J to load multiple threads of a servlet?

    I configured a web site on OC4J that uses a servlet. Everything is working fine.
    Now, I want to start, lets say, 50 instances of this servlet when the web site
    is started by OC4J. How can I do this? Which configuration files should
    I play with? Please note that my servlet is single-threaded and that I want
    all threads running in the same JVM.
    I want to do something similar than this parameter in JServ:
    singleThreadModelServlet.initialCapacity=100
    Thanks

    oc4j/orion is the fastest servlet engine on the planet. Those
    guys in Sweden don't let you mess around with the number of
    servlet instances available. The message here is that you do not
    have to resort to any tricks that other servlet engines use to
    make sure your servlet will be available to be served up...it
    will.
    The only thing that slows it down are lack of memory or lack of
    resources (the database isn't replying fast enough). You can
    solve these problems by clustering your servers on several
    machines.
    regards,
    the elephantwalker
    www.elephantwalker.com

  • Spawning Threads inside the Web Container

    What are the ramifications of a developer spawning off threads from a "helper"
    object called from a servlet service() method ?
    Thanks in advance.

    That's what I said, it is not at all advisable but if you know what you
    are doing it can work just fine.
    The biggest issue is migration since the behavior is not defined in the
    spec and thus all vendors can implement it differently and it can change
    from version to version, which in turn defeats the J2EE portability
    advantage.
    That is why I highly recommended using JMX timers since it is going to
    be available on all J2EE servers and then the only vendor dependent
    thing is to get the MBeanServer.
    Dejan
    DN wrote:
    Hello
    I was also doing the same thing from my servlet but using another class which
    extends thread.
    I was using JDBC calls in the new thread , eventhough it worked fine I was getting
    warning messages in the console when I was using WSAD.(websphere studio).
    My app is deployed to WLS , i did not see any messages in WLS.
    When I post this issue in a forum , some one advised me that it is not advisable
    to open up threads from the servlets and this is what he said 'quote'
    so eventually (i.e.
    J2EE 1.4) spun threads from a Servlet accessing a
    database outside of a transaction will not be
    supported either.
    "Deyan D. Bektchiev" <[email protected]> wrote:
    Whit,
    If you are not careful you can very well starve the JVM, lose your
    security, transaction contexts and probably some other bad things I
    don't know about...
    But having said all those scary things, I must admit that we do it all
    the time and don't have any issues with that.
    For most purposes you should try to use the JMX timer service instead
    of
    spawning your own threads. You callback will be called in a different
    thread from the Weblogic thread pool and I guess this will be sufficient
    for most cases.
    Regards,
    Dejan
    Whit Armstrong wrote:
    What are the ramifications of a developer spawning off threads from
    a "helper"
    object called from a servlet service() method ?
    Thanks in advance.

  • Need to spawn multiple Automator app threads

    I have an AppleScript that runs on a folder action when files are dropped in.
    Each item triggers the same Automator app that FTPs the file.
    Problem arises when the files come in faster than the Automator app finishes each FTP job, so some are skipped. If i could have the AppleScript somehow spawn multiple Automator app threads, this would be solved.
    How would you go about solving it (sorry, can't slow down the incoming files)?
      Mac OS X (10.4.7)  

    anyone?

  • How to handle multiple request in the servlet

    how to handle multiple request in the servlet...
    Example:
    java forum...
    i'm login in the java forum at this time 1000 members make login in this....how happended in servlet?
    if we use thread how to implement in servlet ?

    Serlets are already threaded. The application container instantiates the servlet, then uses this instance in a new thread for every use.
    This is the reason that you should use (almost) no instance variables in a Servlet, but rather that (almost) everything should be local to the method.

  • How do i create a single instance of a class inside a servlet ?

    how do i create a single instance of a class inside a servlet ?
    public void doGet(HttpServletRequest request,HttpServletResponseresponse) throws ServletException, IOException {
    // call a class here. this class should create only single instance, //though we know servlet are multithreaded. if, at any time 10 user comes //and access this servlet still there would one and only one instance of //that class.
    How do i make my class ? class is supposed to write some info to text file.

    i have a class MyClass. this class creates a thread.
    i just want to run MyClass only once in my servlet. i am afriad, if there are 10 users access this servlet ,then 10 Myclass instance wouldbe created. i just want to avoid this. i want to make only one instance of this class.
    How do i do ?
    they have this code in the link you provided.
    public class SingletonObject
      private SingletonObject()
        // no code req'd
      public static SingletonObject getSingletonObject()
        if (ref == null)
            // it's ok, we can call this constructor
            ref = new SingletonObject();          
        return ref;
      public Object clone()
         throws CloneNotSupportedException
        throw new CloneNotSupportedException();
        // that'll teach 'em
      private static SingletonObject ref;
    }i see, they are using clone !, i dont need this. do i ? shouldi delete that method ?
    where do i put my thread's run method in this snippet ?

  • How to use EntityManager in a thread inside a J2EE container

    Hi,
    I'm looking for a usage pattern to use an EntityManager inside a thread of J2EE container. I used injection to inject an EntityManager in a EJB3 service and I can use the em with no problem. But the problem occurs when the service spin a thread and operations of the EntityManager (which is obtained using JNDI lookup ) inside that thread always fails.
    What is the correct usage pattern to obtain/use an EntityManager inside a thread of a J2EE container?
    Thanks.

    What you are trying to do should work as long as you are using the Measurement Studio C++ classes in MStudio version 6.0 or later.
    What version of Measurement Studio are you using? Could you post a simple program that demonstrates the problem?
    There is a fundamental limitation in Windows that prevents you from using a Window handle (HWND) in a different thread than the one that created it. However, the Measurement Studio C++ classes (e.g. CNiGraph) are designed to automatically handle accessing the underlying handle from multiple threads. This is done through standard COM marshaling mechanisms and was implemented in version 6.0 of Measurement Studio.
    David Rohacek
    National Instruments

  • Executors.newSingleThreadScheduledExecutor() creating multiple threads?

    While examining a stack trace this morning, I found approximately 250 idle threads labelled "pool-4-thread-###", where ### ranged from 1 to 250 or so.
    I then traced pool-4-thread to a ScheduledExecutorService and underlying ThreadPoolExecutor object created via a call to Executors.newSingleThreadScheduledExecutor().
    There are two types of tasks scheduled on that instance of the Executor. The first is a task which runs twice a day. The second type is something that gets scheduled as the result of a user action, which may occur dozens of times a day.
    Under what conditions can a SingleThreadScheduledExecutor create and leave around multiple threads?
    Thanks in advance,
    Mike Benveniste

    If the thread never completes.
    It's either hanging, or, more likely, has an exit condition that's never being met. Or it's spawning processes that are not completing.
    Simply put a debug statement at the beginning and end of the thread so you can see when (and if) it's starting and stopping.
    You may want to use object.killProcess() prior to starting the next instance to force the previous instance to stop if it still exists.
    bcf

  • Multiple threads on a Master Page CS3

    Hi,
    I have defined a master page containing naturally 2 pages left and right.
    On each page I have set 3 text frames. Top, Middle and Bottom.
    I have threaded the top left to top right, middle to middle and bottom to bottom.
    The idea is to AutoFill the top, then the middle then the bottom.
    I have Placed a text tile into the top text frame with AutoFill (shift in Windows) and it filled up the top text frame correctly creating some 139 pages.
    Back to Page 1.
    Tried to select the middle or bottom text frames....nada.
    Can't do anything with them. They remain dotted unselected text frames and I cannot select them and Place my middle text and bottom text.
    (When I remove the middle and bottom frames on the master page, and define a text frame page 1, I can fill it but without Autofill that would automatically repeat the text frame in the same size and relative position on the following spead pages. I have to manually place text frames page by page with the right size and location and continue filling manually.)
    Any ideas? Can I have multiple threads originating on the master page?
    Many thanks,
    Mickey

    I'm not totally sure I understand your question. Are you trying to have text run from top-left to top-right to center-left to center-right to bottom-left to bottom-right before making a new spread, or are you trying to have three separate sets of threaded text? I sense it is the latter, since you seem to want to place multiple pages before coming back to the next set of frames.
    Master text frames can be somewhat confusing in how they work, particularly if you are used to other applications where you must have a frame selected to place text. In InDesign you don't need to pre-select a frame for any sort of "Place" operation, and the program will even create one on the fly if required at the point where you click a "loaded" cursor.
    Alternately, you can drag a frame with the loaded cursor to your desired size and shape, or, if a frame happens to be available you can use it, including frames on the master page, by moving the loaded cursor over the frame and noting that the cursor itself changes shape to include parentheses. Exactly what happens when you click the loaded cursor depends on what you are placing and the action you take.
    Placing a graphical element uses the top-left corner as the reference, so if you click and release the loaded cursor that will become the top left corner of a frame the size and shape require to place the object at 100% scale. Dragging and releasing the cursor will create a frame the size and shape you drag, and the object will be placed within it with the upper left corner in the upper left, and scaled to 100%. If the frame size does not match the object, it will either have empty space or the object will be cropped.
    Placing into an existing frame is similar, except you can create a frame in advance with scaling or filling rules applied, or even reflection or rotation, along with any effects you might want to add (putting a frame that's pre-styled in this way onto a master page can be a real timesaver in some situations).
    Placing text is a bit different, but similar. If you click and release the loaded cursor, InDesign will create a new text frame with the top edge at the point you click, and the frame will be made to fill the column guides (every page has at least one column that fills the margins) down to the bottom margin guide. Text will fill this frame from the top according to whatever the default frame insets are set to. Default alignment appears not to be honored.
    If you click and drag a frame, that frame will be filled, or if you click over an existing frame, that also will be filled, but in this case any vertical justification options that have been applied to the frame will be honored.
    My students last year discovered what appears to be an un-documented ripple in placing into an existing frame. If you happen to click the loaded cursor on a guide a new frame will be created using the on-the-fly rules (you can actually see the cursor change back to not having the parentheses as you cross over guides) so I always recommend clicking well inside away from the frame edges or any ruler guides when trying to place content into an existing frame.
    Hope that helps.
    Peter

  • Thread ID for servlets implementing SingleThreadModel

    Container creates different instances for every request to a Servlet implementing SingleThreadModel. So I tried to print thread IDs for such a Servlet by calling Thread.currentThread().getId(). I expected different thread IDs for every request to this Servlet. But what I noticed is - the same thread ID is logged several times (I got thread id 98 and 99 more than once). Can someone please explain why this is behaving like that?

    If container creates a thread pool and if it assigns different requests to same thread (fetched from the pool), then what's the point in creating multiple instances of one servlet?

  • Can multiple threads use same transaction concurrently?

              Is it possible that same transaction is being used by multiple threads concurrently
              in WLS? If each thread is doing suspend and resume how does it work? Does the
              transaction implementation support it? Is there a way to do it?
              

    Why you don't tell us some more about your application?
              I'm assuming this is a relatively long running transaction if run
              serially. One common solution is to break this type of workflow into
              several separate transactions with queues between them.
              -- Rob
              Karambir Singh wrote:
              > Is there any workaround for this? I mean to something like explicitly associating
              > the txn with user created threads.
              >
              > "krishna" <[email protected]> wrote:
              >
              >>Transaction context cannot be propagated to user created Threads.
              >>-Krishna
              >>"Karambir Singh" <[email protected]> wrote in message
              >>news:[email protected]...
              >>
              >>>I'm starting a transaction in main thread and this thread spawns three
              >>
              >>threads.
              >>
              >>>I want updates done in main transaction and updates done in three child
              >>
              >>threads
              >>
              >>>to be part of the same transaction. The transaction is finally commited
              >>
              >>by
              >>main
              >>
              >>>thread.
              >>>
              >>>
              >>>
              >>>
              >>>
              >>>"Dimitri I. Rakitine" <[email protected]> wrote:
              >>>
              >>>>What are you trying to do ?
              >>>>
              >>>>Karambir Singh <[email protected]> wrote:
              >>>>
              >>>>
              >>>>>Is there any workaround to do this?
              >>>>
              >>>>>"Dimitri I. Rakitine" <[email protected]> wrote:
              >>>>>
              >>>>>>No, it is associated with a thread which started it.
              >>>>>>
              >>>>>>Karambir Singh <[email protected]> wrote:
              >>>>>>
              >>>>>>
              >>>>>>>Is it possible that same transaction is being used by multiple
              >>
              >>threads
              >>
              >>>>>>concurrently
              >>>>>>
              >>>>>>>in WLS? If each thread is doing suspend and resume how does it
              >>
              >>work?
              >>
              >>>>>>Does the
              >>>>>>
              >>>>>>>transaction implementation support it? Is there a way to do it?
              >>>>>>
              >>>>>>--
              >>>>>>Dimitri
              >>>>>>
              >>>>
              >>>>--
              >>>>Dimitri
              >>>>
              >>>
              >>
              >
              

  • How to Buffer JSP Output Inside A Servlet

    Hello, we are trying to Process a JSP page inside a servlet and then do more processing and finnaly add the JSP output to the response output stream. I know there is a RequestDispatcher that lets you include a JSP page. However as far as I know all you can do with the RequestDispatcher is either include the JSP (which does not buffer it but simply adds it to the output stream) or forward to the JSP page. Any ideas? Thanks, - dk

    http://forum.java.sun.com/thread.jsp?forum=33&thread=377214

  • Multiple Threads and Loggers

    I have a program that spawns off multiple threads. I want each thread to have its own logger and file name. The catch is that the file names must be dynamic.
    Basically, each thread should have its own log file.
    I'm using commons-logging.
    I know one suggestion is to let it all log into one file, and then parse afterwards. I figured that if the only way the log file is readable is in its parsed form, why not try to create these parsed files from the program itself.

    dewalt wrote:
    I have a program that spawns off multiple threads. I want each thread to have its own logger and file name. The catch is that the file names must be dynamic.
    Basically, each thread should have its own log file. Sounds like a bad idea to me.
    I know one suggestion is to let it all log into one file, and then parse afterwards. I figured that if the only way the log file is readable is in its parsed form, why not try to create these parsed files from the program itself.Because if you are spending all your time reading a log file then either there is something seriously wrong with your code or something seriously wrong with your requirements.
    You read a log file because there is a problem in production.
    So now you have 20 or 300 log files to look at just to find the problem. And operations has to collect those 20 or 300 files so you can look at them in the first place. (Or maybe 40 to 600 because the problem happen sometime between yesterday and today.)
    Then you have to assume that there is absolutely no intentional interaction between the threads at all. Because if there is then obviously you are going to be looking at more than one file (and finding it) anyways.
    And what if there is an unintentional interaction? How are you going to even figure that out, since you won't have a semi-accurrate timeline of all the threads running at that time.....without puting all of the log files back together.

Maybe you are looking for

  • This report for Vendor Balance Reconcillation.......

    Hi Seniors, Please help me with this issue........i have to develope a New report Vendor balance Reconcillation ......Using the Standard report S_ALR_87012082 vendor balances in local currency.....it should be same like this Standard report but this

  • How can I get contacts to update from Facebook if I have them in my email account as well?

    Hello, I'm running iOS 8 on my iPhone 6.  I have contacts coming down from several email accounts as well as Facebook. For contacts that exist both from an email account and Facebook, the Facebook data doesn't sync down.  So I don't get, for example,

  • 500 Server Error when executing Query in Portal

    When I run a query in the ABAP Web all the components (the pulldowns) work as well as the query executes. When I run the query in the Java WebI get a 500 Internal Server Error com.sap.ip.bi.base.application.exceptions.AbortMessageRuntimeException: Te

  • Updating a book through iTunes for Windows

    I purchased and downloaded a book through the iTunes Store, and it has since been updated.  My understanding is that I will need to delete the book from my library, and download it again, with this download being the updated version? I have been noti

  • Need help with OS10.8

    I just "successfully " installed Mountain Lion on my 13" MacBook late 2009. At least I thought it was successfully installed.  But now, every few seconds the screen "brightens" and then it restarts. I can not open anything on my computer.  Has anyone