Brace yourselves, this could get complicated: The basic issue is this: I am concerned about the thread saftey of my Custom Tag. I have a tag that has one "property" called page. Hence, here is the basic outline of my custom tag: public class MyTag extends TagSupport{ private String page; /** Actual evaluation of the tag occurs here. */ public int ... |
|
Hi all!! what u have to say about threads safety in the folowing code sample, as my applcation is running fine if accessed by a single user but causes problems such as reslultset is closed or invalid cursor state....etc.(if accessed by multiple users concurrently..) please help!!! Lusha <%response.setContentType("text/html"); response.setDateHeader("Expires",0); response.setHeader("Cache-Control","no-cache"); response.setHeader("Pragma","no-cache"); %> <%@ page language='java' import='java.sql.*,javax.servlet.*,javax.servlet.http.*,java.io.*,java.sql.*,java.util.*' %> <% ... |
Hi, I have heard people talking about creating only local variables in doPost,doGet methods for Thread Safe access. In some situations I need to call other methods from doPost, but beacuse of thread safty concerns I am passing all the variables to the called methods. Like for instance in doPost doPost(...){ // vector is a Vector // request is of typeHttpServletRequest ... |
Ken, "name" is an instance variable for "Action". But, since the "action" instance is a local varible in Servlet so it is thread safe, i.e. no two thread can access the same "action" object at the same time, then this "action" instance belongs to one thread only. So from client point of view, any instance varible of this "action" instance is ... |
In the case where only one thread writes an atomic object and only one thread reads it, there's not much of an issue. Advanced thread-control issues come into play only where there's a possibility of the value being referenced is in the middle of being updated. However, you haven't said how you're going to connect the querent with its thread. There's ... |
|
|
Arrrggghhh.... No, final does not make it thread-safe. The best way to make your WHOLE servlet thread-safe is to NOT use any instance variables -- what were you planning on putting in that variable, anyway? Kyle BTW, do a search here on Javaranch and you'll find this question is answered quite completely every two weeks or so... |
Hi Daniel Basically an instance of a servlet class (and consequentially a JSP) can handle multiple simultaneous HTTP requests. On receipt of an HTTP request for a URL the Web Container will invoke the appropriate service method (i.e. doGet, doPost() ) on the servlet that is 'listening' on the URL. The simplest way to ensure that a servlet can handle multiple ... |
|
|
We are currently writing a system which parses data into PDF output via Apaches FOP. This is done in a Servlet which needs to load data into variables and whoses process takes a reasonable amount of time i.e 5-10 seconds. This data is accessed by many of the methods used in the servlet. The system can be used concurrently by many ... |
|
|
|
If I have a Central Servlet called "MainServlet.java", in its doGet method I have public void doGet(...,...) { handleFile() // open a file and write to the file } public void handleFile() { // open file // write something on it // close the file } Now my concern is --- Since this "MainServlet" can be called simultaneously by everybody using ... |
What I got from reading HFS&J is, There is only one way to make context attribute thread safe, where ever we are using context (setting and getting attrubute in context) in whole web application, do that in synchronized block. Other than this, there is no way to make sure... Am I right? Thanks. |
The session object on the server is associated with a single user via the session id passed between them, but there is no guarantee that the user cannot have multiple browser windows using the same session token. You just can't enforce that. Therefore if the user opens the same page in two windows and submits both with same data at the ... |
|
|
|
Hi Guys, I currently have an application I'm working on where users add work log entries through a standard form. They can add multiple entries and then click save which adds the entries to a database. While they are adding new entries they can view all their old entries and delete or update any of them. I'm currently storing all of ... |
|
|
The easiest first step to having a threadsafe servlet is to avoid the use of instance variables. Declare all of your variables in the doGet or doPost method. Overuse or improper use of the synchronized keyword can cause bottlenecks in your app. You may, occasionally need to synchronize access to session or context scoped variables but this should be rare. |
|
|
|
|
Objects are not thread-safe - code is. HttpServletRequest objects are only safe to use in multiple threads if the code that handles them is. Since each incoming HTTP request is handled by a separate thread in the servlet container, each HSR object is safe unless your code starts using it in several threads (which would be an unusual way of doing ... |
I search the forum and on the internet, but seems there is no thread answering my doubt. So I would like to post a new thread to make clear. I have a servlet, which in turns call another class (e.g. class X{...} ), in which there is a class variable (e.g. static Map map = Collections.synchornizedMap(..)). In servlet, all variables are ... |
I have been trying to implement some practices and good framework for maintaining future code in my servlets, that i have been using in core java. I feel that i have done everything right to keep the servlet thread safe. Just looking for a second opinion. Always parinoid about locking threads. Thanks John package admin; import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; ... |
|