Question: Multi Threaded Routing Module Servelet
See original GitHub issueHow do you create a multi-threaded routing module servelet so all available CPU cores are utilised?
Also in the routing module servelet how do you make a distinction on what type of request is made when the method
is not provided? Within this context how can parameters be accessed?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
15+ Java multithreading interview questions & answers
Java multithreading interview questions & answers explain beginner level concepts like heap vs stack, re-entrant, synchronized keyword, ...
Read more >Servlet and JSP Tutorial | How to Build Web Applications in ...
Introduction to Servlets. Servlet is a server-side Java program module that handles client requests and implements the servlet interface.
Read more >how to use Servlet in multithread environment - Stack Overflow
All you have to care about is to makeyour servlet code thread-safe. And the best way to do it is to let it...
Read more >Chapter 2 Using Servlets
The automatic routing in an HTTP servlet is based simply on a call to request.getMethod(), which provides the HTTP transfer method. In a...
Read more >What are some of the toughest Java multi threading questions?
1. Implementing Runnable over extending Thread(from composition over inheritance perspective) 2. Synchronized collections vs concurrent collections(how they ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello, @sirinath
RouterModule
is supported only for single-threaded servers. You have to map servlets to corresponding paths by hand, similarly to example from this replyYou can read a cookie directly from a request by calling either
@Nullable String getCookie(String)
- to read a single cookie orMap<String,String> getCookies()
- to retrieve all of the cookies from a requestYou can refer to API of HttpRequest if you need help with accessing cookies or other request parameters. Or you can look at examples on the website that I have provided in previous reply.
Modules.combine()
allows you to combine bindings from different modules as if it is a single module. If your application has several modules, you could useModules.combine()
to return a single module fromgetBusinessLogicModule()
method orgetOverrideModule()
.If you specify a duplicate binding in
getBusinessLogicModule()
you will catch an exception, as bindings with same keys are forbidden. However, if you want to override existing bindings with your own, you can usegetOverrideModule()
for this. For example, you can override default Config provided inHttpServerLauncher
by overridinggetOverrideModule()
and returning a module that contains binding for a new Config.You can refer to documentation for more information. Or you can look at API/javadocs of Injector, Launcher or HttpServerLauncher
Hello, @sirinath Yes, you can use routing servlet in multithreaded context. The preffered way is to specify all of the mappings directly. If you wish, you can omit HTTP method while configuring routes in
RoutingServlet
. You can determine a method of HTTP request based on result ofrequest.getMethod()
call. But it is more convenient to specify the method to be handled. Mappings that do not specify HTTP method are primarly useful for providing fallback servlets, or for combining with other routing servlets that have mappings for multiple methods.Here is a snippet that demonstrates how to do that:
Note how HTTP method of the request is accessed in
/allMethods
mapping. An API servlet that has mappings for different methods is mapped to/api/*
endpoint that does not specify HTTP method. As a result, requests are correctly passed to the API servlet to be handled.To learn more about servlets and how parameters are handled, please refer to examples: Multithreaded server Request parameters Routing servlet