Does anyone know if there is a way to dynamically (runtime) increase the stack size of the main Thread? Also, and I believe it is the same question, is it possible to increase / update the stack size of a Thread after its instantiation?

Thread’s CTOR allows the definition of its stack size but I can’t find any way to update it. Actually, I didn’t find any management of the stack size in the JDK (which tends to indicate that it’s not possible), everything is done in the VM.

According to the java language specification it is possible to set the stack size ‘when stack is created’ but there is a note:

A Java virtual machine implementation may provide the programmer or the user control over the initial size of Java virtual machine stacks, as well as, in the case of dynamically expanding or contracting Java virtual machine stacks, control over the maximum and minimum sizes.

IMO that’s not very clear, does that mean that some VM handle Threads with max (edit) stack sizes evolving within a given range? Can we do that with Hostpot (I didn't find any stack size related options beside Xss) ?

Thanks !

解决方案

The stack size dynamcally updates itself as it is used so you never need to so this.

What you can set is the maximum size it can be with -Xss This is the virtual memory size used and you can make it as large as you like on 64-bit JVMs. The actual memory used is based on the amount of memory you use. ;)

EDIT: The important distinction is that the maximum size is reserved as virtual memory (so is the heap btw). i.e. the address space is reserved, which is also why it cannot be extended. In 32-bit systems you have limited address space and this can still be a problem. But in 64-bit systems, you usually have up to 256 TB of virtual memory (a processor limitation) so virtual memory is cheap. The actual memory is allocated in pages (typically 4 KB) and they are only allocated when used. This is why the memory of a Java application appears to grow over time even though the maximum heap size is allocated on startup. The same thing happens with thread stacks. Only the pages actually touched are allocated.

java改变线程堆栈大小,在运行时更新java线程的堆栈大小相关推荐

  1. 基于 Java 2 运行时安全模型的线程协作--转

    在 Java 2 之前的版本,运行时的安全模型使用非常严格受限的沙箱模型(Sandbox).读者应该熟悉,Java 不受信的 Applet 代码就是基于这个严格受限的沙箱模型来提供运行时的安全检查.沙 ...

  2. new,is和as运算符解析及运行时类型,对象,线程堆栈,托管堆之间的联系

    CLR要求对象必须使用new运算符创建,在使用new运算符创建一个对象时具体都做了些什么呢? 1.计算所有定义的实例字段,所有的基类型包括System.Object需要分配的字节数. 每一个堆上的对象 ...

  3. 2020 idea 查看内存消耗_查看运行时某个java对象占用JVM大小及通过idea查看java的内存占用情况...

    一.如果想看运行时某个java对象占用JVM内存大小,可以先将对象转换成字节类型,然后计算: List bizGroupRelatedEventInfos = bizEventVersionMappe ...

  4. 在运行时修补Java

    本文将重点介绍如何解决与第三方库相关的问题 不能被规避 难以排除/绕过/替换 只需不提供错误修正 在这种情况下,解决问题仍然是一项艰巨的任务. 作为这种情况的诱因,请考虑对"哈希索引&quo ...

  5. 常见运行时异常 java 114982568

    常见运行时异常 java 114982568 空指针异常 类型转换异常 算术异常 数组下标越界异常

  6. 常见的运行时异常 java 1615309080

    常见的运行时异常 java 1615309080 空指针异常 变量没赋值时,引发 数组越界异常 类型转换异常 数字格式化异常 算术异常 检查时异常

  7. java运行库一键修复_在运行时修补Java

    java运行库一键修复 本文将重点介绍如何解决与第三方库相关的问题 不能被规避 难以排除/绕过/更换 只需不提供错误修正 在这种情况下,解决问题仍然是一项艰巨的任务. 作为这种情况的诱因,请考虑对&q ...

  8. 在 Visual Basic 6 中让用户在运行时移动和调整控件大小

      标题 在 Visual Basic 6 中让用户在运行时移动和调整控件大小 描述 此示例说明如何让用户在 Visual Basic 6 中在运行时移动控件和调整控件大小. 关键词 拖动.移动.调整 ...

  9. [Unity脚本运行时更新]C#7新特性

    洪流学堂,让你快人几步!本文首发于洪流学堂微信公众号. 本文是该系列<Unity脚本运行时更新带来了什么?>的第5篇. 洪流学堂公众号回复runtime,获取本系列所有文章. Unity2 ...

最新文章

  1. seaborn使用violinplot函数可视化水平小提琴图(Make Horizontal Violin Plot with violinplot in Seaborn)
  2. mysql建立的一个自动更新组织树案案例
  3. 如何在Kubernetes中暴露服务访问
  4. 企业微服务:搭建环境
  5. 手动造轮子——为Ocelot集成Nacos注册中心
  6. Chapter2-1_Voice Conversion(Feature Disentangle)
  7. Titanic(泰坦尼克号生存预测)---(1)
  8. java string的某个字符_JAVA如何提取String中字符串的某个字符 具体内容
  9. Quartz定时调度CronTrigger时间配置格式说明与实例
  10. css如何将元素水平居中
  11. ZetCode Ruby 教程
  12. golang mysql scan_golang 实现 mysql 数据库备份
  13. 权限管理Ranger
  14. 不少同学想要放弃秋招了........
  15. C++11 线程对象创建后既不join()也不detach()的后果
  16. linux man page
  17. 查询表空间建立表空间和删除表空间
  18. c语言课程设计高校水电费管理系统
  19. android编译错误记录
  20. 计算机三级数据库技术——第一章 数据库应用系统开发方法学习笔记

热门文章

  1. 拖动卡顿_教你4招,让你的ps永不卡顿
  2. win8 打开计算机配置,win8.1 更改电脑配置无法使用
  3. c mysql命令_最基本的mysql命令
  4. 8年php薪資,8年PHP求稳定远程团队带走
  5. mysql update from 语句_MySQL高频面试题01期:一条update语句的生命历程
  6. i css svg,如何设置 CSS 背景图中的 SVG 的颜色
  7. mysql 查看collation_MySQL collation方法
  8. nb模块不能接收公网消息_物联网连接技术之NB-IOT无线技术介绍
  9. php ajax 长轮询 表单,Thinkphp结合AJAX长轮询实现PC与APP推送详解
  10. pythonc代码_Python实现C代码统计工具(一)