Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you need to set the database thread pool size to 1(id it let's you), and also make Servlets as single thread, but there is no warranty about the queue, maybe the second one in a queue goes before first, and why do you need to do it so?</p> <p>another way is that every requests are filtered by a servlet filter that that filter lock a synchronized object from beginning till end response, this ensures you no any other thread would take the lock and do the same (at least for http requests)</p> <p>servlet single thread mode:</p> <pre><code>public class AloneServlet extends HttpServlet implements SingleThreadModel { //.... } the servlet filter approach public final class HitCounterFilter implements Filter { private Object lock=new Object(); //... public void doFilter(ServletRequest request,ServletResponse response, FilterChain chain) synchronized(lock){ chain.doFilter(request, wrapper); } } } </code></pre> <p>the two samples above are for http requests, you need to do same for web-services, or etc.</p> <p>please tell why do you want your server goes single thread, maybe there are more better approach available, I never suggest these approaches :)</p> <p><strong>Approach 2:</strong><br> first code the filter code</p> <pre><code>package com.stackoverflow.supportbuddy import javax.servlet.*; import javax.servlet.http.*; // Implements Filter class @ServletFilter(urlPatterns={"/pages/myJSP.jsp"})// for Java EE 6+ public class SyncFilter implements Filter { public void init(FilterConfig config)throws ServletException{} @Override private static Object lock=new Lock(); @Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws java.io.IOException, ServletException { //each thread needs to lock the "lock" object and this ensures you only one thread will be forwarded. synchronized(lock){ chain.doFilter(request,response); } } @Override public void destroy( ){} } </code></pre> <p>then map the filter to desired jsp file, for example if <code>jsp</code> file is located under <code>/pages</code> folder, then you need to map the filter as this in <code>web.xml</code> or using annotation in newer version of Java EE</p> <pre><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"&gt; ..... &lt;filter&gt; &lt;filter-name&gt;SycnFilter&lt;/filter-name&gt; &lt;filter-class&gt;com.stackoverflow.supportbuddy.SyncFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;SycnFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/pages/myJSP.jsp&lt;/url-pattern&gt; &lt;/filter-mapping&gt; ..... &lt;/web-app&gt; </code></pre> <p>finally have a try :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload