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.

Similar Messages

  • ServerSocket(TCP/IP) listening in the web container part

    So, if I implement the ServerSocket(TCP/IP) listening in the web container part (Websphere), what is the best way to do this?
    I need to monitor socket state and statistics from browser.
    When I receive message from socket, I must read something from database and send as response to client (meaning I need to create my own thread to do this).
    Solution:
    - to have one servlet with serverSoket listener in it or
    - during web application statup to start my own thread with serverSoket listener
    - or....
    Also there is a problem that websphere write warning when i try do use DB connection from thread I have created!
    Any suggestion?

    hi,
    do you use websphere? version?
    More details:
    http://www.javaranch.com/newsletter/200403/AsynchronousProcessingFromServlets.html
    According to a Technical note from WebSphere support "If a Servlet is spinning its own threads and accessing a database, the J2EE specification is not clear on this, so WebSphere Application Server 5.0 will allow it at this time. IBM is working with Sun to clarify this in the specification, so eventually (i.e. J2EE 1.4) spun threads from a Servlet accessing a database outside of a transaction will not be supported either". Later the same tech note states "Customers should consider changing their application to comply with the J2EE specification."
    and check this
    http://www-1.ibm.com/support/docview.wss?uid=swg21121449

  • How to view the session in the web container

    hi, Folks,
    is there any way to view the sessions in J2EE web container? I need to know how many living session currently in the web container.
    Thanks

    You did not indicate the Web Server version that you are using for web container. Assuming its Sun Java System Web Server 6.1, per Servlet 2.3 specification, you should be able to use of session creation and destruction events. This can be done using HttpSessionListener to count active sessions. Here's the docs for reference:
    http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpSessionListener.html
    Thanks
    Manish

  • RFC: Introduce new 'Article/Tutorial (Comment) Threads' in the Web Dynpro Forum

    Some time ago I've suggested on SCN Support is both forum moderator and most active articles wrtiter
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net
    Message was edited by: Bertram Ganz
    This thread was branched from forum thread: How to print the data of a Model node.

    Hi Valery,
    thanks for this great idea. Indeed, there is no channel set up to communicate feedback/suggestions/questions to Web Dynpro tutorials or articles in a standardized way.
    WebLogs can be commented on the WebLog page itself and they are announced in a special ;\ New Web Dynpro Weblogs which can be opened via the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d">Web Dynpro Feature2Sample Matrix</a>. Actually the section 'Further Information' lists all related articles, WebLogs etc. These links are regularly updated so that the Sample Description Pages helps to keep all links to valuable information in a central place.
    The 'Sample Description Page' should additionally comprise a section <b>'Discussion'</b> with a link to the above 'Article Comment Thread' in the Web Dynpro forum. The reader downloads the material from the sample description page and also finds a link to the related 'Article Comment Thread' there.
    For all new articles (which are combined with a related 'Article Comment Thread') the <i>Further Information</i> links could point to the 'Article Comment Thread' (which then itself links to the article) but not directly to the article resource. The reader can then also have look at the existing comments to the related resource. As an alternative the article PDF itself should have a permanent link to the 'Article Comment Thread' in the Web Dynpro Forum.
    Please post your comments on this idea.
    Regards, Bertram

  • How to run a report out of the web container?

    Hi All,
    <p>
    Does anyone have tips on running a report outside of the web container?  I'd like to be able to JUnit the scenarios I'm coding up without having an app server running.  What is the ReportClientDocument expecting in the request, response, and context?  The code as shown just returns the enclosed error.
    <p>
    All I'm really trying to do is have the report execute and be able to assert that the data is appropriately retrieved from the data source.  If there's a way to do that without the Viewer, that would be cool, too.
    <p>
    Any tips would be much appreciated.   Sorry about the poorly formatted code and error... the code tags don't seem to be working...
    <p>
    Thanks,
    <p>
    Eric
    <pre>public void testReportRunning() throws ReportSDKExceptionBase{
              ReportClientDocument rcd = initReportClientDoc("./test/data/EBTest1.rpt");
              assertTrue(rcd.isOpen());
              CrystalReportViewer crv = new CrystalReportViewer();
              crv.setReportSource(rcd.getReportSource());
            String htmlContent = crv.getHtmlContent(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockServletContext());
            System.out.println(htmlContent);
    com.businessobjects.report.web.shared.WebReportingException---- Error code:0
         at com.businessobjects.report.web.e.if(Unknown Source)
         at com.businessobjects.report.web.e.a(Unknown Source)
         at com.crystaldecisions.report.web.ServerControl.a(Unknown Source)
         at com.crystaldecisions.report.web.ServerControl.a(Unknown Source)
         at com.crystaldecisions.report.web.ServerControl.getHtmlContent(Unknown Source)
         at com.tririga.crystalpoc.ReportAccessorTest.testReportRunning(ReportAccessorTest.java:82)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at junit.framework.TestCase.runTest(TestCase.java:164)
         at junit.framework.TestCase.runBare(TestCase.java:130)
         at junit.framework.TestResult$1.protect(TestResult.java:106)
         at junit.framework.TestResult.runProtected(TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:120)
         at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)</pre>
    Edited by: Eric Batzdorff on Jun 12, 2009 12:24 AM
    Edited by: Eric Batzdorff on Jun 12, 2009 12:24 AM
    Edited by: Eric Batzdorff on Jun 12, 2009 12:25 AM

    There's no documentation as to what's the minimum HTTPServletContext, HTTPServletRequest and HTTPServletResponse the CrystalReportViewer expects. 
    There certainly are plenty of unit testing frameworks for Java Web Apps out there, if that's where you're headed.
    Sincerely,
    Ted Ueda

  • Do I must put ALL my servlets inside the web.xml file?

    Hello everybody,
    I am trying to migrate from Webshere to TOMCAT a project with severals packets, one of those have 15 servlets and some classes.
    Is there any way to use the servlets without have to declare each one inside the web.xlm file ?
    Thanks in advance.

    All servlet definitions go into web.xml, though not the actual servlets themselves :) . Say if you wanted servlet A to have a different mapping you would define the mapping in web.xml to something other than the standard one.

  • Security BUG in the web container!

    Hello,
    I have just accidently discovered a security BUG in the web container. The bug permits you to view the source of the JSP page (welcome page).
    To reproduce the bug, do the following:
    1. Create a web application. Create new page with name Index.jsp. Add "Index.jsp" into the web.xml as a welcome file.
    2. Deploy it under, let's say, "SecurityBugWebApp".
    3. Access http://host/SecurityBugWebApp/ or http://host/SecurityBugWebApp/Index.jsp - everything should be as usual - you should see a normal output of a JSP page.
    4. Access http://host/SecurityBugWebApp/Index.JSP (notice the case of the ".JSP" ). You should be able to see the source code of the web page. This bug even works if it is under security constraint! This doesn't seem to work, however, with JSPs not listed in the welcome file list.
    Sincerely,
    Sergei Batiuk.

    Peter,
    Thank you for your suggestion. This makes sense to
    try. I'm actually using a trial license of AS7 with
    no updates. I've found update 1 online with free
    trial, however, do you know if AS7 update 2 is
    available with a trial license and where it might be
    located for download?
    you can get AS7 update2 Platform edition from here.
    Platform ed. is FREE for both development and production deployment
    http://wwws.sun.com/software/download/products/3fb01655.html
    AS7 update2 Standard Edition can be downloaded from here.
    Standard Ed is free only for development, you need to buy a license to use it in production.
    http://wwws.sun.com/software/download/products/3f7df408.html
    Peter

  • 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

  • Threads running in web container

    How to get current web container active threads count,and how to get the max web container thread count ,in weblogic

    Hello Slava,
    The output you see when running to web from Reports Builder is controlled by the web source of your report. Please take a look at your web source and confirm whether that the reports JSP tags are indeed present to fetch the data and format the web output.
    Also, note that if you want to deploy your report using its web layout, you would need to save it as a JSP, as only JSPs can be deployed directly over the web.
    RDF files can be run over the web only using rwservlet, and doing so will cause the output to be formatted using the report's paper layout instead of it's web layout.
    Thanks,
    The Oracle Reports Team.

  • 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

  • Drop Shadow Filter hiding inside the Hbox container

    Hi,
    I have an HBox with roundedRectangle skin inside a repeater
    in a vertical layout. HBox has drop shadow filter applied on it.
    Problem is that, as repeater is executing the drop shadow is
    getting hid by next HBox created below the previous Hbox. I want
    the shadow on the top of next HBox.
    Code Snippet:
    <mx:Repeater id="myrep" dataProvider="{myAC}">
    <mx:HBox borderSkin="RoundedRectangle"
    backgroundColor="0xB9C3C9" backgroundAlpha="1"
    horizontalGap="0" cornerRadius="10" width="80" height="80"
    verticalGap="2" >
    <mx:filters>
    <mx:DropShadowFilter distance="14" angle="45" blurX="10"
    />
    </mx:filters>
    </mx:HBox>
    </mx:Repeater>
    Any way to solve it?

    "nit_vs" <[email protected]> wrote in
    message
    news:gi854o$qn5$[email protected]..
    > Hi,
    > I have an HBox with roundedRectangle skin inside a
    repeater in a
    > vertical
    > layout. HBox has drop shadow filter applied on it.
    Problem is that, as
    > repeater
    > is executing the drop shadow is getting hid by next HBox
    created below the
    > previous Hbox. I want the shadow on the top of next
    HBox.
    > Code Snippet:
    > <mx:Repeater id="myrep" dataProvider="{myAC}">
    > <mx:HBox borderSkin="RoundedRectangle"
    backgroundColor="0xB9C3C9"
    > backgroundAlpha="1"
    > horizontalGap="0" cornerRadius="10" width="80"
    height="80"
    > verticalGap="2" >
    > <mx:filters>
    > <mx:DropShadowFilter distance="14" angle="45"
    blurX="10" />
    > </mx:filters>
    > </mx:HBox>
    > </mx:Repeater>
    > Any way to solve it?
    >
    Draw them from the bottom up, or change the childIndex of
    each one after
    it's drawn.

  • Exact functions of Servlet context and servlet Config inside web container

    What is the correct(exact) function in the Servlet Context and Servlet Config inside the Web Container?.
    Pls anybody response me.
    -- Palani

    ServletConfig:
    The container reads the servlet init-parameters specified in web.xml then adds them to ServletConfig. The container then passes ServletConfig to the servlet. Thereafter, the servlet can access the ServletConfig and get the servlet init-parameters. The idea is that you can avoid hard coding data that might change in your servlet code, e.g. an email address. If the email address changes, you can change it in web.xml instead of having to hunt through all your code and change the email address every place it appears and then recompiling the servlet.
    Servlet init-parameters in web.xml are targeted for one servlet.
    ServletContext:
    The ServletContext is an app wide bulletin board where you can post data. Other parts of your app, e.g. other servlets, can then read the data on the bulletin board.
    Also, similar to ServeltConfig, the container reads context-init parameters from web.xml and inserts them into ServletContext. However, in this case they are inserted into an app wide bulletin board, and therefore all servlets can read them.
    An example: you might put database connection info in some context-init parameters. Then when the ServletContext is created, you can have "a listener" respond to the ServletContext creation event and get the database info, create a database connection, and attach it to the ServletContext. Then the database connection will be available to any servlet that needs it.
    palanithendral wrote:
    What is the correct(exact) function in the Servlet Context and Servlet Config inside the Web Container?.
    The exact function of each would be determined by the group of methods each one provides. You need to check the java docs to see what each method does.

  • Configuration of Thread Pool for CQ's Web Container

    I am trying to detrmine whether there is any specific configuration for tuning the web container thread pool for CQ. The only configuration I observe is OSGi 's Apache Sling Event Thread Pool but tuning this does not directly correlate to the thread pool that is used for serving web requests by the publish instance.
    Any help would be greatly appreciated as I work through tuning our CQ instance.

    Unfortunately, the max thread settings is not exposed in CQ 5.5.However, all the other configurable settings (equivalent for server.xml) can be seen at [1]
    [1] http://localhost:4502/system/console/configMgr/org.apache.felix.http
    This is fixed in CQ 5.6 current release.
    Thanks,
    Varun

  • Using Local EJB obect in web container that installed in on the same Web AS

    we can use the local ejb object in the application that runs in same JVM.
    The Web Container and EJB Container run in the same JVM when Web AS installed as Minimum Cluster Installation(one cluster node).
    But, what happened if we install the Web AS as Large Cluster Installation? Can we still use the local ejb objects in the Web Container?
    Best regards,
    Raja
    Message was edited by: Raja Nasrallah

    Hi Raja,
    Yes you can. When you use local EJB objects there's no remote communication and the web container will find them in the EJB container of the local cluster node. For the application providers this is transparent - they shouldn't care about the configuration of the cluster.
    Best regards,
    Vladimir
    PS: Please consider <a href="https://www.sdn.sap.com/sdn/index.sdn?page=crp_help.htm#lostme">rewarding points</a> for helpful answers.

  • Trouble compiling java files inside the packages.

    Hello I have a question in Java when compiling with packages. Can anyone Help??
    My 2 java files BeerSelect2.java & BeerExpert.java are in packages com.example.web & com.example.model respectively.
    C:\MyProjects\beerV1\src\com\example\web\BeerSelect2.java
    and
    C:\MyProjects\beerV1\src\com\example\model\BeerExpert.java
    I have compiled the BeerExpert.java in the model package.(ie the class file for BeerExpert is in the com.example.model package.)
    My BeerSelect2 file which is inside the web folder is like this
    package com.example.web;
    import com.example.model.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class BeerSelect2 extends HttpServlet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    out.println("Beer Selection Advice<br>");
    String c=request.getParameter("color");
    out.println("<br> Got Beer color "+c);
    BeerExpert be=new BeerExpert();
    List result=be.getBrands(c);
    response.setContentType("text/html");
    out.println("BEER SELECTION ADVICE <br>");
    Iterator it=result.iterator();
    while(it.hasNext())
    out.print("<br> try: "+it.next());
    This shows 3 comile errors.
    & the BeerExpert.java file which is in the model folder is like this:
    package com.example.model;
    import java.util.*;
    public class BeerExpert
    public List getBrands(String color)
    List brands=new ArrayList();
    if(color.equals("amber"))
    brands.add("Jack Amber");
    brands.add("Red Moose");
    else
    brands.add("Jale pale Ale");
    brands.add("Gout Stout");
    return (brands);
    This compiles fine in the model folder.
    Now when I'm trying to compile my BeerSelect2.java in the 'web' folder in which I'm trying to import the com.example.model.* which is as follows
    C:\MyProjects\beerV1\src\com\example\web>javac BeerSelect2.java
    which gives 3 errors like this
    BeerSelect2.java:3: package com.example.model does not exist
    import com.example.model.*
    ^
    BeerSelect2.java:22:cannot find symbol
    symbol: class BeerExpert
    location: class com.example.web.BeerSelect2.
    BeerExpert be=new BeerExpert();
    ^
    BeerSelect2.java:22:cannot find symbol
    symbol: class BeerExpert
    location: class com.example.web.BeerSelect2.
    BeerExpert be=new BeerExpert();
    ^
    Can anyone help???

    Since the classes are part of the com.example.web and com.example.model packages the most straight forward way to compile is from the folder containing "com". Assuming you want the resulting .class files to be in the same folders are their associated .java source files:
    C:\MyProjects\beerV1\src\> javac -cp . com\example\model\BeerExpert.java
    C:\MyProjects\beerV1\src\> javac -cp . com\example\web\BeerSelect2.javaThe -cp . part is there to set the classpath (the location that the compiler will use to locate java classes) and thereby let the compiler make sense of the import statements.
    The presence of "src" in the directory path strongly suggests, however, that the intention is not to have source and class files end up in the same directory. If this is the case read up on the syntax of the http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html (java.exe) and http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html (javac.exe) commands. (paying attention to how searching for types is done). Also read up on any documentation you were given for building the application (if you are modifying something already given).
    If you are using an IDE you should say.

Maybe you are looking for

  • Macbook Pro 15" USB PORT DOESN'T RECOGNIZE ANY DEVICE.

    I got my macbook pro 15" for about 1 year and 2 weeks ago, when I turned on my macbook and put my mouse ( Death Adder) into the USB PORT, my macbook DOESN'T RECOGNIZE IT. There are 2 usb ports on my macbook, I tried both port and there was only one p

  • Mismatch of version of external and kernel dp lib

    Hello All i'm trying to uppgrade a was abap kernel 7.00 from version 133 to 16 on  db2 udb database. I use the files: SAP Kernel 700 64-Bit, Unicode, AIX64bit - FOR ECC60 Landscape: SAPEXEDB_146-20000977.SAR SAPEXE_146-20000978.SAR lib_dbsl_156-20000

  • Fonts when sending Reports via Printer Option (10g Reports / Redhat 5)

    When I send a Oracle 10g report to the printer, which PPD file is it using? The printer you install on the server or the one in ORACLE_HOME/guicommon/tk/admin/PPD directory? I installed a printer on the Linux Server and copied the file to the ORACLE_

  • Error with StringTokenizer

    hi, i am receiving the following error message: MyBot.java:611: cannot resolve symbol symbol: class StringTokenizer location: class MyBot           StringTokenizer t = new StringTokenizer(s,"@"); repeated twice, with one arrow pointing at the first m

  • CS3 flash gallery issue - Safari /Firefox

    Can anyone tell me why after creating my flash gallery in cs3  photoshop why in Fireflox and in Safari it says this at the top of each  page= Please upgrade your Flash Player. Already have Flash Player? Click here if you have Flash Player 6  installe