Set Java call stack

一曲冷凌霜 提交于 2019-12-11 19:28:24

问题


is it possible to modify/access the Java call stack ? For instance saving and restoring ? I'm thinking about implementing cooperative multitaskting (especially I/O) just like gevent for python or haskell (which does this natively). The async callback spaghetti mess can't be the best solution.


回答1:


The simplest solution is to have multiple threads. You can have up to 10,000 threads running efficiently on a server. If you need much more than this, I would suggest either a) buying a second server, or b) using non-blocking IO.

In general, using multiple threads is the simplest and for small numbers of threads, is the fastest too.

There are libraries to do this in Java in various manners. They all suffer from a common problem, they are either slower, or much more complicated or both.

BTW I make this point because when a thread context switch it does exactly what you suggest, but the OS does it for you.



来源:https://stackoverflow.com/questions/17975897/set-java-call-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!