pippo icon indicating copy to clipboard operation
pippo copied to clipboard

Thread model?

Open robertoestivill opened this issue 9 years ago • 4 comments

Hello everyone, Im investigating Pippo for some projects and I couldn't find any information about the threading model. And by that, I mean how are routes/controllers instantiated and maintained throughout the request/response/process lifecycle, in order to ensure code thread safety. As a developer, do I have to worry about thread safety at all ? or thread safety is provided by the framework (like, for exaple, vertx) ? If we have to handle this manually, is there any advice, good practice, documentation or guide written about this? Thank you!

robertoestivill avatar Apr 14 '16 23:04 robertoestivill

I don't think you need to worry about thread-safety as long as you do not use instance variables in Route

ScienJus avatar Apr 15 '16 02:04 ScienJus

Right, but what if you do? An example would be any heavy/long initialization object: like a connection pool for example. Maybe It makes sense to create it only once and reuse between executions, instead of creating the connection every time the controller is executed. I am not saying this is the case of pippo, but because I do not know what the model is, i can not be sure. I guess the question is towards understanding what the instance lifecycle is for the different components and manage the threading based on that.

robertoestivill avatar Apr 15 '16 02:04 robertoestivill

I have a mistake in last comment, in pippo Route is a singleton instance, but Controller will be created a new instance for each request and thread. so if you have some heavy/long initialization object for a handler, you can create it in Route, but if you need to use it in Controller, you should give a singleton instance or use ioc container like pippo-spring

ScienJus avatar Apr 15 '16 06:04 ScienJus

Information posted by ScienJus is right. If you need more details please let me know. Also, if you see some improvements I would be happy to encapsulate them. I will improve the documentation related to this subject.

decebals avatar Apr 15 '16 19:04 decebals