简体   繁体   中英

Java multithreading with web sockets

I have a web application where the front end communicates with the backend through websockets. I want to multi thread each request coming from the front end. ie; as soon as a socket request comes from the front end, I should create a separate thread for it so that it runs concurrently. I have a class that keeps track of each request and delegates the work to other class based on the request parameters. I want to multi thread the request processing. How should I start with it. I have knowledge about threads but I dont know the right approach to proceed.

Your approach is extremely bad. I can't stress how bad it is.

you should read about asynchronous IO and find a suitable Java library which supports (real) asynchronous Websockets.

A Thread per request is a recipe for server which can't handle more than few thousands request at a time. it was a popular approach back in the days, but ditched in favor of asynchronous IO + small threadpool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM