本文介绍了方法在哪里生活?堆还是堆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道方法的局部变量和参数在堆栈中,但是我无法弄清楚在Java中方法实际在哪里?

I know that local variables and paramters of methods live in stack, but I not able to figure out where does actually methods live in case of Java?

如果我声明任何Thread对象,如:

If I declare any Thread object like:

Thread t=new Thread();
t.start();

因此,这意味着除了主方法之外,我还创建了一个单独的方法调用.这是什么意思?这是否意味着在堆栈内存上调用单独的方法序列?我说的对吗?

So it means I've created a separate calling of methods apart from main method. What does it mean? Does it mean calling of separate sequence of methods over Stack memory? Am I right?

推荐答案

每个线程都分配有自己的堆栈.

Each thread is allocated its own stack.

本文有很好的介绍Java进程中的内存分离.

This article has a good introduction to the memory separation within a Java process.

我已经看到许多场景,其中客户端基于每个线程只做很少的事情实现了线程数量巨大的服务器,并且它们遇到了内存问题.那是因为每个线程都分配有自己的堆栈,并且(显然)加起来了.我认为的默认值为每个线程512k,但是我没有找到规范的来源.

I've seen many scenarios where clients have implemented hugely threaded servers on the basis that each thread does very little, and they run into problems with memory. That's because each thread is allocated its own stack, and this (obviously) adds up. I think the default value is 512k per thread, but I've not found a canonical source for that.

这篇关于方法在哪里生活?堆还是堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:05