May i know how are Threads created by web container (New thread is created for every request) different from normal Threads which are created by Extending Thread Class or implementing Runnable Interface. Also how does Web container create Threads,even when Servlet interface or the servlets Extending it doesn't contain any run() method.
Difference between Threads created by web container and Normal Threads?
3.2k Views Asked by Kumar At
2
There are 2 best solutions below
0
Shailesh Yadav
On
There is no difference between threads except that in case of web container threads are generally taken from thread pool, as Creating a new thread object every time is expensive and time consuming.
(Thread pool is a collection of pre-instantiated, idle threads which stand ready to be given work, usually organized in a queue).
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in MULTITHREADING
- new thread blocks main thread
- WPF MessageBox Cancel checkbox check
- How to avoid concurrent access to a resource?
- run oncomplete event in async
- Threading Segfault when reading members
- Function timeouts in C and thread
- How are multiple requests to Task.Run handled from a resource management standpoint?
- Acumatica perfomance with threads
- Wait and Notify in Java threads for a given interval
- Different behavior of async with Visual Studio 2013(Windows8.1) and GCC 4.9(Ubuntu14.10)
- How to return blocking queue to the right object?
- background thread using Task.Run
- deletion and cleanup of worker thread in Qt crashes
- Pipeline-like operation using TChan
- implementing in app purchase on android
Related Questions in SERVLETS
- Redirect inside java interceptor
- Which Should i use for date,time,email in servlet?
- Importing a downloaded JAR file into a Servlet
- Execute RequestDispatcher after 5 seconds
- What's the difference between a ServletHandler and a ServletContextHandler in Jetty?
- How to call servlet file from html
- Requested Resource is not available error
- Struts exclude pattern with spring
- How can I get a custom header from the client in Tomcat?
- How to print Jasper reports from servlets?
- The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved
- ServletContext Attribute : Thread Safety test not working
- Servlet ClassNotFoundException when present in a package ... Why?
- How to create a PDF with iText+XMLWorker from servlet using custom font?
- Starting a ScheduledExecutorService from a servlet with a set of parameters
Related Questions in WEB-CONTAINER
- Spring com Web Container Java ou Application Server?
- Why should I use cookies other than for storing a session id?
- web application and process in web container in java
- Access to the httprequest object within POJO called by WebSphere Command/JSP/etc?
- what does context mean with respect to a web-container / a web application?
- Servlet thread pool vs Servlet instance pool - by the web container
- Is there Web Container custom property com.ibm.ws.webcontainer.suppresserrorpageodrheader="true" equivalent in Open liberty?
- Websphere Live Sessions vs Active Sessions
- Is stackblitz's terminal using the host or external processing power?
- StackBlitz - ECONNREFUSED when connecting to local machine
- What happens when WebContainer thread pool (WebSphere) is fully used and new request is received?
- Spring Project inside EJB project
- Develop a web application in java EE using only a servlet container?
- Difference between Threads created by web container and Normal Threads?
- Dynamically loading or replacing jars in a Webcontainer (Tomcat)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
All the threads in java are created by Extending Thread Class or implementing Runnable Interface. So web container threads are also created in same way.
You dont see run method inside servlet, that's because servlet code is called inside run method of thread which is created by "main" thread of container. Container abstracts all these details, so that we can focus on writing actual logic server by request instaed of worrying about multiple request management.
Every container has "main" thread, the way we have for our standalone application, or similar to SpringMain in spring.
IF you want to to distinguish between container threads and your threads, you can look at their names and you should find a pattern. You can control nomenclature of threads created by your business logic.