Java守护程序线程是否与生成过程共享堆或Perm生成? [英] Does a Java Daemon Thread Share Heap or Perm Gen with Spawning Process?

查看:82
本文介绍了Java守护程序线程是否与生成过程共享堆或Perm生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从程序(非守护程序进程)创建了守护程序线程,堆和perm gen内存空间是否与新线程共享或重新分配?



如果守护程序线程获得了自己的空间,那么在创建新线程时是否应遵循JVM内存调整参数(例如最大堆大小等)?

解决方案


是新线程共享的堆和perm gen内存空间还是新分配的内存?


所有线程(守护程序状态无关紧要)共享堆和perm内存空间。每个线程都有自己的堆栈空间,用于存储方法字段和调用堆栈。您可以通过更改JVM参数。但是,即使这些堆栈区域也是一般JVM堆空间的一部分。



当线程在单独的CPU中运行时,它们也具有内存 cache 。每CPU内存高速缓存用于性能原因,因此出于速度原因可以对本地CPU内存进行更新,而不必在每次访问时都将信息同步到中央存储。但是这些缓存仍然可以读取和写入常规JVM内存空间。



有关守护程序线程真正含义的更多信息,请参见@Peter的答案。 p>

If I create a Daemon thread from my program (a non-daemon process), are the heap and perm gen memory spaces shared with the new thread or is it allocated anew?

If the daemon thread gets its own spaces, are the JVM memory tuning args like max heap size, etc respected in the creation of the new thread?

解决方案

are the heap and perm gen memory spaces shared with the new thread or is it allocated anew?

All threads (daemon status does not matter) share heap and perm memory spaces. Each thread has it's own stack space which it uses to store method fields and the call stack. You can tune the size of the allocated per-thread stack space by changing JVM arguments. But even these stack areas are part of the general JVM heap space.

Threads also have a memory cache when it is running in a separate CPU. The per-CPU memory cache is used for performance reasons so updates can be made to local CPU memory for speed reasons without having to synchronize the information to central storage on every access. But these caches still read from and write to the general JVM memory space.

For more information about what daemon-thread really means, see @Peter's answer.

这篇关于Java守护程序线程是否与生成过程共享堆或Perm生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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