JSP it self doesn't need synchronization, but the objects you use in it. The output of the number crunching is a simple table. JSP is basically a single method in a servlet. Java Servlet life cycle is managed by the servlet container.
Truong Ha 3, 8 28 If you absolutely have to have EL offers a simpler way to invoke Java code but he code itself belongs somewhere else. I need to create a new thread from JSP. A JSP could not that it should contain arbitrary Java, which may not be thread safe.
The one thing to note is that if your Java code needs to use any other class that it is in the classpath just like a normal Java program. Thread-safety with servlets is achieved by having no private fields in the servlet - the servlet instance is one for the whole container and each request is a new thread invoking the service.. Spawn thread from servlet? I would like to ask, what does the threads share?
I guess it would help our fellow developers who search for same question and seek answer. I have a servlet, that calls a web service, and gets data to populate the servlet response. The servlet are executed by some threads. This method is called from the servlets service method which means its runs in a separate thread for each request, the container passes the request and response object to this method.
What u can do is, donot have many private or public variables. Use local variables declared inside your doGet or doPost - they are automatically Thread-safe. As you may know already, methods are thread safe, the the sense, that two threads invoking the same method of the same object at the same time, will execute each one in its own stack.
Bozho k 99 I should also say, that if you structure your application as MVC then all thread-unsafe code is called from the controller and the view the JSP never needs to be unsafe. Use local variables declared inside your doGet or doPost - they are automatically Thread-safe. Sign up using Email and Password. I want to create a Thread safe JSP page.
You would fix it, right? The servlet are executed by some threads. Please correct me if i am wrong. Suppose that I have a method called doSomething and I want to use this method in a multithreaded application each servlet inherits from HttpServlet. I wanted to know if it is possible for me to do the database access and simultaneously navigate through other pages in the software. What you must be aware of, is, objects put into the session, or the context may be accessed by multiple threads at the same time, or pretty much not thread safe code.
Servlets should not start threads due to issues that may arise when clustering Your JSP can call code which may not be thread safe. Instead use the session capabilities provided by the servlet container servlet engine - as Tomcat.
If you declare a variable a in a JSP, there is no way, another request sees that variable. So, you don't really need to make a thread safe JSP, because, it is trade safe already. Please correct me if i am wrong. You would fix it, right? I would like to ask, what does the threads share? I've got a jsp and currently when the user hits a button on
I've been asked to fix up a Servlet that sits in between two applications. One thing I like about JSP is include mechanism. I have a system that I need to distrubte that works as follows. I want to create a Thread safe JSP page. Thread-safety with servlets is achieved by having no private fields in the servlet - the servlet instance is one for the whole container and each request is a new thread invoking the service..
Java Servlet life cycle is managed by the servlet container. You would fix it, right? Sign up using Email and Password. This process takes a long time and the page is blocked till then. Anyhow letme say something about my xperience with servlets. In JSP, just use variables in scriplets and you can be confident that they are thread safe because they will be translated into local variable in service.
- JSP declarations are for declaring members of the generated servlet class. So instead of having the Presumbly you would be doing that exactly because the Servlet code is not thread safe, that is if more than one thread were to get at the code bad things would happen. You should specify exactly what you mean by thread-safety in your case - i. The output of the number crunching is a simple table. You will get fired into oblivion when you're doing so in real business world.
- Added a clarification about it. Truong Ha 3, 8 28 If this is the scenario, with your JSP needing to use that existing legacy code, somewhere in your JSP you have a call that unsafe stuff: Sign up using Email and Password.
Objects that are accessible to more than one servlet instance at a time, such as instances of HttpSession, may be available at any particular time to multiple servlets, including those that implement SingleThreadModel. Sign up using Facebook. Hi, I dont know if my reply will help u in any way. This implies to me that you have something like this in the servlet code: In JSP, just use variables in scriplets and you can be confident that they are thread safe because they will be translated into local variable in service. Hi, I have a JSP page which does database mysql access to retrieve data.
Join Stack Overflow to learn, share knowledge, and build your career. This implies to me that you have something like this in the servlet code: Each jsp invoked within the loop does a lot of number crunching that takes time at the server end.
I'm new to jersey, jsp's and web application development in general so hopefully this isn't a silly question. Obviously, it is still the responsibility of the developer to ensure that synchronous access to thread unsafe regions of code. Email Sign Up or sign in with Google. Setting a value of false, will get the container to synchronize access to page level objects and not to session and application scoped objects or objects of any other variety. Sign up using Email and Password.