java - How server spawns new thread for a singleton object in spring framework -
i have been working on spring framework controller / service / repository annotations , each class singleton. whenever request comes server , server has spawn new thread corresponding controller class ( singleton ) each thread have own stack execute same method of class in different stacks.
when see controller class neither implement runnable class nor extending thread.
i know code behind this. how server spawns thread singleton controller class.
will done reflection or anonymous thread or other method. please post example code.
the server doesn't need spawn new thread every new request, wasteful , not scalable. has fixed pool of threads sit , wait new requests. whenever such request arrives, server delegates processing 1 of idle threads. part of processing calling method on (already existing, singleton) object.
so, there's no need controller
or service
runnable
. 1 of working threads awakes, calls method on class (its stack temporarily growing during calling) , goes pool of available threads wait next request (this time, stack resets state of idle waiting).
this post on threads reusing might of interest you.
Comments
Post a Comment