Thread Button in servlet
Hi All,
I want to have a servlet or jsp page which has several buttons named 'Start'.
On clicking a 'Start' button, it should generate a thread (in another class) and run a process and the button will become 'stop'.
On clicking the stop button, the thread should stop. I can click any button at any time and start the thread and stop in at any time.
Can anyone tell me any technique for this problem?
Regards,
Pradhip
i can't find why a nullPointerException occurs if i don,t see the code!
Similar Messages
-
Thread pool in servlet container
Hello all,
I'm working on this webapp that has some bad response times and I've identified an area were we could shave off a considerable amount of time. The app is invoking a component that causes data to be catched for subsequently targeted apps in the environemnt. Our app does not need to wait for a response so I'd like to make this an asyncronous call. So, how best to implement this?...I considered JMS, but started working on a solution using the Java 1.4 backport of JSR 166 (java.util.concurrent).
I've been testing the use of a ThreadPoolExecutor, using an ArrayBlockingQueue. The work that each Runnable will perform involves a lot of waiting (the component we call invokes a web service, among a couple other distributed calls). So I figure the pool will be much larger than the queue. Our container has 35 execute threads, so I've been testing with a thread pool size of 25, and a queue of 10.
Any thoughts on this approach? I understand that some of this work could be simplified by JMS, but if I don't need to be tied to the container, I'd prefer not to. The code if much easier to unit test, and plays nicely with our continious build integration (which runs our junit test for us and notifies on errors).
Any thoughts are greatly appreciated...Thanks!!Well, if it works, that's by far the best way to go - but note that creating threads in a servlet container means those threads are outside of the container's control. Many containers will refuse to give the new threads access to the JNDI context, even, and some may prevent you from creating threads at all.
-
I cannot find the new thread button to ask a question
I just installed Firefox and need help but but cannot get to the New Thread button option to ask a question.
How do I get there?Through the back door?
You just asked a question so you can let us know what's up with Firefox.
For future reference, you can ask a new thread at support.mozilla.org/questions/new and simply go through the prompts.
Also, if you lost a thread you were on, you can go to your profile and see your questions and answers by clicking your username at the top of any support.mozilla.org page. Your account is located at https://support.mozilla.org/en-US/user/1082275 -
Threads spawning in Servlets allowed?
Hello to all servlet afficionados,
I am following thread discussions already a while and there's always
discussion whether to user threads or not (I am not talking about a
servlet thread but about threads manually instantiated for other
reasons like asynchroneous handling of tasks for loose coupling or for
long running purposes).
So here's my question:
Is it definitely allowed to spawn threads from a servlet (and even put
the reference into the application context to allow others to later on
access that thread)?
Does the jdk specify on this?
Or Is it even specific for each servlet engine? What is BEA saying
about this?
And even further: Is this different on application servers that
include an ejb-container? Again, does the specification say something
about this? What does BEA say about this?
Thanks for trying to find out the real truth :-)
regards
Stefan
Stefan,
There is nothing in the Servlet spec that specifically prohibits the use
of threads within a servlet, but most will tell you that you should avoid it
if possible. Having said that, I've seen quite a few implimentations that
use background threads for tasks such as log queue processing and have not
really had any issues. To me it's a matter of degree. As long as your
architecture makes sense and you are careful to avoid potential deadlocks,
you should be ok. FWIW, BEA recommends not creating threads within a web
application.
-chris
"Stefan Hoehn" <[email protected]> wrote in message
news:[email protected]...
> Hello to all servlet afficionados,
>
> I am following thread discussions already a while and there's always
> discussion whether to user threads or not (I am not talking about a
> servlet thread but about threads manually instantiated for other
> reasons like asynchroneous handling of tasks for loose coupling or for
> long running purposes).
>
> So here's my question:
>
> Is it definitely allowed to spawn threads from a servlet (and even put
> the reference into the application context to allow others to later on
> access that thread)?
>
> Does the jdk specify on this?
>
> Or Is it even specific for each servlet engine? What is BEA saying
> about this?
>
> And even further: Is this different on application servers that
> include an ejb-container? Again, does the specification say something
> about this? What does BEA say about this?
>
>
> Thanks for trying to find out the real truth :-)
>
> regards
> Stefan
-
Starting new threads from a servlet
Hi
I read somewhere that starting new threads from a servlet is not supported in the future releases of J2EE .
Any one aware of this.
I have a listener program started as a new thread from the init method of a servlet which is set to load on startup.
I have to think about another way to do this if this is not suppported in the future releases
any commentsDr clap
Actually I was getting some warning messages in my websphere server console when I tried to make JDBC connections from the thread I opened in the servlet.
Everthing works fine but with the warning messages,
Then someone from IBM answered me in one of the forums quote
Cause: These messages are being produced due to an
"unsupported" environment. When application is
spinning its own threads from an EJB, spinning a
thread and accessing a database is not supported (per
the J2EE specification). One exception to this rule is
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 must allow
for 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.
Since we don't want to promote the usage of these
"naked" threads accessing databases, we are producing
the warning messages. Although they may be filling up
the logs, we feel that these are necessary to warn the
user that they are doing something not in-line with
the intended usage. Customer should consider changing
their application to comply with the
J2EE specification.
""" -
How to handle more than one submit buttons on servlets
Hi:
anyone know how to handle the multiplet submit button on servlet,
such as next, previous, add and so on.
Thank youDon't worry about because only the button that is clicked will get submitted. In the servlet you just test for the existance of a parameter:
if (request.getParamter("SubmitButton1") != null) { ..... }
if (request.getParamter("SubmitButton2") != null) { ..... }
Save the following HTML code, open in IE and click on the buttons to see what will get sent to the servlet:
<html><head></head><body>
<form method="GET">
<input type=text name=text1>
<input type=submit name="Submit1" value="Me">
<input type=submit name="Submit2" value="you">
</form>
</body></html> -
Here is the problem that i am trying to solve - and get better understanding of issues to look out for.
1) Problem to solve
Clients sends an http request to an distributor server. The request contains a list of tasks. Each such task can be sent to a particular handling server (out of a known set) which can handle the request. Each task has a task type, which identifies which server the request needs to be passed to. The responses from the handler servers are then to be collected and passed back the client as a consolidated response.
On the distributor server, the servlet thread that is handling the request will
a. need to spread the requests for various handling servers
b. send the requests in parallel to handling servers
b. get all the responses , consolidate and send back
2)Proposed solution
I was thinking of having a thread pool - one thread for each handling server, initialized within servlet . When the distributor server receives a request - the tasks would be spread to these handling threads. The distributor thread would then wait, until the handling threads notify.
When a notification is received - the distributor thread will need to check if all responses are received. If not - it would need to wait (till a max_timeout) else return the response to client
3)Questions
- This involves waiting on the thread created by serlvet container (the distributor thread) and creating a threadpool. Thread creation and management by application in web-container is generally dissuaded - but given this issue - i see no other alternative
suggestions ? Its been a long email - thanks for considering
FredHow many clients for the entry server do you presume for the application ? I ask this because it is very possible that the server to remain without available threads and give errors. If you use different servers for the final requests I suppose that are some very time consuming processes. What kind of application are running on these servers so that you want to use this kind of distributed computing ?
Why did you choose as an entry point a servlet container and http request for this kind of problem ? Do you need a graphic response in the browser ? If the response time is too long, the browser (Internet Explorer) will show exception and will not wait for the response (for this you must set some variabiles on client). Also the J2EE server must be set so that not to throw a time-out exception.
To prevent these, you could do so that not to block the distributor thread and let it send the answer back to the client. Then you can tell to client browser to query the server from time to time to check the status of the execution (you can do that from javascript). When the execution is ready you can retrun the response to the client. Doing this way you will not block the application server threads.
Now in the back end, you must somehow to take some identificators from the processes and sent them back to the client.
You can use a database to make the bridge between the central server and the other processes (here you can put the processes identificators). When the processes end up they update their results in the database.
The client, when will make the repetitive requests, will check the status of the processes in the database with given identificators.
Sounds like an interesting project. -
1. Is there any limit on maximum no of threads that would be created for a servlet by default? (I'm using Tomcat 3.2) If yes, what is the value of this limit?
2. How can I change this limit in Tomcat 3.2? Is there any difference in the configuration of this limit for Tomcat 3 and Tomcat 4?
3. If I increase the maximum no of threads, what OS level limitation would I need to take care of? Like default socket close timeout or what else ...
AnkitLook in the server.xml file. If you are running tomcat in standalone on port 8080 search the server.xml file for '8080'. Here you will find the configuration options for the connector. The maxProcessors and minProcessors setting set the number of threads that tomcat will use for requests on this connector.
For more information check the tomcat documentation. -
Hi all,
I am facing a big problem while doing a concurrent testing of my web application.
I am testing with 60 concurrent users.
I have set the database connection pool minimum capacity to 50, capacity increment
to 10 and maximum capacity to 100.
While there is no problem in getting database connection, the session variables
are getting mixed up (i.e. the session variable for one user is coming up as that
for another user!!!).
Does it have something to do with configuring some pool for servlets threads or
something?
Please help.
Thanks a lot in advance and best regards,
Jaya
Hi all,
I am facing a big problem while doing a concurrent testing of my web application.
I am testing with 60 concurrent users.
I have set the database connection pool minimum capacity to 50, capacity increment
to 10 and maximum capacity to 100.
While there is no problem in getting database connection, the session variables
are getting mixed up (i.e. the session variable for one user is coming up as that
for another user!!!).
Does it have something to do with configuring some pool for servlets threads or
something?
Please help.
Thanks a lot in advance and best regards,
Jaya
-
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
Thanksoc4j/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 -
Single Threaded Model JSP- Servlet
Servelts can be set to have thread safe access (Single thread model). However, when a JSP is converted in to a servlet, is the servlet tagged as to use the single thread model?
As of JSP specification 1.2 the default value for the "isThreadSafe" attribute of the page directive is true indicating that the container can direct multiple requests to the page simultaneously. If this value is set to false then the requests will be sent one at a time.
Good Luck!
Eshwar Rao
Developer Technical Support
Sun microsystems inc
http://www.sun.com/developers/support -
Restricting Thread Pool for Servlet instances
I am using WebLogic5.1.0 version wherein I am registering a Servlet which
would be called by all the clients connecting
to my aplication. The servlet's service methods is taking some time to
execute. Since the servlet is following a SingleThreadModel, when there are
a large number of Clients connected, the number instances of Servlets
created are very high and the number of thread in the Application Server
process becomes very high affecting the performance of the other
applications.
Is it possible to restrict the number of instances of the servlets that get
created in the Application server ?
What are the setting required to achieve this ?
SandeepHi.
I'm not aware of a property setting that allows you to restrict the number of
servlet instances in WLS for the SingleThreadModel. The number of execute
threads is fixed - it does not grow depending on load. You can set this value
in the weblogic.properties file by setting weblogic.system.executeThreadCount.
This value is 15 by default.
It does sound like you are reaching the max capability of your
server/hardware. You should try tuning WLS.
Here are a couple of suggestions:
1. Try adjusting the executeThreadCount value to a higher value. Start by
setting it to 30 - see if that makes any difference.
2. Check out the following tuning guide:
http://www.weblogic.com/docs51/admindocs/tuning.html
3. Here is a list of admin properties that might aid in tuning:
http://www.weblogic.com/docs51/adminhelp/AdminPropertyHelp.html
4. If you are still having problems you might do better by posting this issue
to the performance newsgroup.
Regards,
Michael
Sandeep Rajpathak wrote:
I am using WebLogic5.1.0 version wherein I am registering a Servlet which
would be called by all the clients connecting
to my aplication. The servlet's service methods is taking some time to
execute. Since the servlet is following a SingleThreadModel, when there are
a large number of Clients connected, the number instances of Servlets
created are very high and the number of thread in the Application Server
process becomes very high affecting the performance of the other
applications.
Is it possible to restrict the number of instances of the servlets that get
created in the Application server ?
What are the setting required to achieve this ?
Sandeep--
Michael Young
Developer Relations Engineer
BEA Support -
Adding a Button a Servlet that calls a JSP
How would one put a Button in a Servlet that directs to a JSP.
... I have created a servlet that displays records from a database, but I would like to add a button that returns to a JSP page.
I thought something like this would help...
out.println("<input type='submit' value='Return to Main Page' name='response.sendRedirect ('MainPage.jsp');'/>");Help...
Edited by: Gusha on 11-Oct-2008 13:23You edited your message with a code snippet:
Gusha wrote:
out.println("<input type='submit' value='Return to Main Page' name='response.sendRedirect ('MainPage.jsp');'/>");
Couple of things:
1) Presentation logic belongs in JSP, not in Servlet. Using out.print in either JSP or Servlet is a bad practice.
2) Java runs at server side, not at client side. -
Ejb lookups fail from threads spawned from servlet
Hello,
We have a servlet from which we are spawning a thread. In the thread we are
trying to do a JNDI lookup for the database resource / EJBs. It does not
work as if it is not able to find the context t do the lookup.
I thought that the threads are spawned in the same JVM and context, so why
does the lookup not work.
Please need to figure out a solution to this problem, we need to call some
business logic in the EJBS from the thread and we do not want to do RMI-IIOP
lookups becuase they could be slower.
Appreciate your help in advance.
Regards,
SakibCustom threading is not supported. I think a workaround was posted on
this alias (search for custom threading), where you can call the
proprietary API's of the container to recreate the context, but I'm
pretty sure that it's not a supported or recommended solution.
The better (and more scalable) solution is to avoid spawning your own
threads.
David
Sakib Mehasanewala wrote:
Hello,
We have a servlet from which we are spawning a thread. In the thread we are
trying to do a JNDI lookup for the database resource / EJBs. It does not
work as if it is not able to find the context t do the lookup.
I thought that the threads are spawned in the same JVM and context, so why
does the lookup not work.
Please need to figure out a solution to this problem, we need to call some
business logic in the EJBS from the thread and we do not want to do RMI-IIOP
lookups becuase they could be slower.
Appreciate your help in advance.
Regards,
Sakib -
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?
Maybe you are looking for
-
Ipod not being recognized in Itunes
Ever since I upgraded to latest Itunes version, but Ipod mini is not recognized in Itunes. I know I've seen other postings, but I've tried everything that has been suggested that nothing seems to work. There is nothing wrong with the Ipod mini or cab
-
Short dump 'DBIF_RSQL_SQL_ERROR' in R/3 system
Hi, In the daily extraction process in BW a load process(infopackage) fails due to short dump "DBIF_RSQL_SQL_ERROR" in the source system(R/3) side. The load getting the 20000 records but the process failed due to above error. i have made the request
-
Process rfc in background workprocess
Hi all, i hve to call a function module in background workprocess but when i called a fm simply without specify background then it's give me right o/p . CALL FUNCTION 'Y_WS3_ALIASTEST' but after specify background then it's giving no values CALL
-
Need help with dreamweaverMX tutorial
I am using dreamweaverMX tutorial with coldfusion free edition developement. On dreamweaver, when I tried to insert a record on the server behavior panel, I get this message saying: "This server behavior requires a Coldfusion data source". Please Hel
-
[Solved] Grub Menu at boot How to remove?
There is a pesky dialog box that starts when the computer starts. It is open for 4 seconds then moves on. It says something about choosing a grub and gives two options. It automatically defaults to the first option after 4 seconds. Does anyone know h