设置Java调用堆栈 [英] Set Java call stack

查看:78
本文介绍了设置Java调用堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以修改/访问Java调用堆栈?例如保存和恢复?我正在考虑实现协作式多任务处理(尤其是I/O),就像python或haskell的gevent(本机执行此操作)一样.异步回调意大利面条混乱不是最好的解决方案.

解决方案

最简单的解决方案是拥有多个线程.您最多可以在服务器上有效运行10,000个线程.如果您还需要更多,我建议a)购买第二台服务器,或b)使用非阻塞IO.

通常,使用多个线程是最简单的,对于少量线程,也是最快的.

有很多库可以用Java的各种方式来做到这一点.它们都遇到一个共同的问题,它们要么变慢,要么变得更加复杂,或者两者兼而有之.

顺便说一句,我之所以这样说是因为,当线程上下文切换时,它会完全按照您的建议进行操作,而操作系统会为您进行操作.

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.

解决方案

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.

这篇关于设置Java调用堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆