I want to host a application from home. My local machine: Core i7 2600 4 core,8 thread and 16GB memory Fiber: 100Mbps
My Target: 100k workerthread, each thread have its own while loop.
Will my machine survive. Code Sample:
serversocket obj_sock=new serversocket()
while(true){
new thread(new workerthread(obj_socket.accept());
}
class workerthread implements runnable{
public workerthread(socket sock){
rs=sock.getinputstream()
ws=sock.getoutputstream()
}
public void(run){
while(true){
//do read stream, write stream
}
}
}
PS I skipped exceptions in code.
The default thread stack size on my 64-bit Java 8 is 1M. That means that 100,000 threads will need 100G of RAM to work with. That is tunable, and you could probably get under 16G, but software would require more testing with a constrained stack.
It seems like operating systems will let you create that many threads.
I would strongly suggest looking into an event-driven (ie non-blocking) protocol framework like Netty or Apache MINA to implement your server.
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.