首页 \ 问答 \ 闲置时JVM锯齿图案?(JVM sawtooth pattern when idle? what does the JVM do in the meantime?)

闲置时JVM锯齿图案?(JVM sawtooth pattern when idle? what does the JVM do in the meantime?)

我在想。 我有一个简单的Java Web项目和一个servlet。 当没有用户使用它(我在GlassFish上本地托管它)时,我仍然在该进程的内存使用情况中看到锯齿图案。 我似乎无法理解JVM在做什么? 我了解JVM使用的内存的正常流程。 堆正在充满应用程序正在创建的对象。 在某个时间点,堆会到达垃圾收集器进入的点,这将删除所有不再使用的“缓存”对象,以便可以创建新对象并且可以填充堆大小。

我想知道的是,JVM闲置时一直在做什么? 在这里输入图像描述

编辑:

就像我在评论中所说的那样。 我在Eclipse中创建了一个非常简单的Java应用程序,该应用程序显示一个Swing窗口,显示“hello world”。 当我在Java VisualVM中观察JVM的内存使用情况时,我看到了相同的锯齿图案。


I was wondering. I have a simple Java web project with a servlet. When no users are using it (I host it local on GlassFish) I still see a sawtooth pattern in the memory usage of the process. I can't seem to understand what the JVM is doing? I understand the normal flow of the memory used by JVM. The heap is getting filled with objects the application is creating. At a certain point the heap reaches a point where the garbage collector comes in, which will remove all the 'cached' objects which no longer are used, so that new objects can be created and can be filled in the heap size.

What I wonder is, what is the JVM doing all the time when it's idle? enter image description here

EDIT:

Like I said in the comments. I created a very simple Java application in Eclipse which showed a Swing window saying 'hello world'. When I watch the memory usage of the JVM in Java VisualVM, I see the same sawtooth pattern.


原文:https://stackoverflow.com/questions/12958219
更新时间:2023-10-28 14:10

最满意答案

该模块有点搞砸了。 它应该遵循这种模式:

var sliderJS = function(sliderID) {

    //define private functions here eg. setEventListeners

    //Return an object containing functions that are public eg. doSlide
    return {
        doSlide: function(type, e){

        }
    };
};

所以你不需要new关键字,只需调用:

var slider1 = sliderJS("mySliderJS2");

但是,如果您创建了大量实例并希望获得更好的性能,那么最好创建一个函数并填充其原型 - 然后您可以使用new关键字调用该函数。


The module is a little bit messed up. It should follow this pattern:

var sliderJS = function(sliderID) {

    //define private functions here eg. setEventListeners

    //Return an object containing functions that are public eg. doSlide
    return {
        doSlide: function(type, e){

        }
    };
};

So you don't need the new keyword, just call:

var slider1 = sliderJS("mySliderJS2");

If, however, you're creating a lot of instances and would prefer better performance, you'd be better off creating a function and populating its prototype - then you can call that function with the new keyword.

相关问答

更多
  • 我创建了一个名为augment的库,它将模块模式与原型继承相结合。 例如,你可以使用augment实现你的Anagram “类”如下: var augment = require("augment"); var Anagram = module.exports = augment(Object, function () { this.constructor = function (original) { this.original = original.toLowerCase(); ...
  • 构造函数和原型是实现类和实例的合理方式之一。 它们并不完全对应于该模型,因此您通常需要选择特定的方案或帮助方法来实现原型方面的类。 ( JS中的类的一些背景 ) 模块模式通常用于命名空间,其中您将有一个实例充当存储来分组相关的功能和对象。 这是一个不同的用例,从什么原型是有益的。 他们不是真的相互竞争; 你可以非常高兴地一起使用(例如在模块中放置一个构造函数,并说出new MyNamespace.MyModule.MyClass(arguments) )。 Constructor-functions and ...
  • 模块模式不是类模式。 你不能简单地假装你现在有JavaScript的课程。 至于继承,如果你真的需要继承东西,你应该通过构造函数创建一个对象并使用原型继承,尽管它有时候执行起来会比较慢。 至于创建子模块很简单 MODULE.submodule = (function(){ // another module stuff that can even reference MODULE return { submodule: 'property' } })(); 现在,就古典意义上的子类化而言, ...
  • 函数本身的属性就像static类成员(函数的属性,而不是它的实例) function prototype属性在不同实例中是不同的: function test(){}; test.prototype = { constructor : test, first : '', second : '', third : '', init : function(f, s, t){ this.first = f; this.second = s; ...
  • 该模块有点搞砸了。 它应该遵循这种模式: var sliderJS = function(sliderID) { //define private functions here eg. setEventListeners //Return an object containing functions that are public eg. doSlide return { doSlide: function(type, e){ } }; ...
  • 是的,模块是单身人士。 一辆汽车只有一个发动机。 创建第二个根本没有意义(除非你从根本上改变整个设计,增加任何struts可以承担的负载等)。 第二种模式是“类”模式,其中有许多行为相似的实例(想想一堆汽车)。 Yes, modules are singletons. A car has just one engine. Creating a second one simply doesn't make sense (unless you radically change the whole design, ...
  • 虽然这段代码按预期工作,但最近我发了一篇文章,如果你有多个实例,这个模式会占用大量内存 您在第一个代码段中显示的代码是单例模块,没有“多个实例”。 这完全没问题。 只有标题为Module pattern - Multiple instances的东西Module pattern - Multiple instances小提琴中的Module pattern - Multiple instances在实例化大量对象时会遇到内存缺陷 。 但是,请注意,这不是“模块模式”,而是“工厂模式”。 现在我想知道使用Re ...
  • 我的假设是只使用后一种方法,因为由于闭包能够使用私有变量..? 我对么? 是。 如果你需要私有变量。 第一种方法不使用闭包,因此位于全局内存范围内,不能拥有私有成员。 但请注意,即使在第二个示例中, s变量也是不必要的全局变量。 那么为什么CSS Tricks和其他人使用第一种方法作为例子,当它似乎没有任何真正的目的? 为简单起见。 当你没有局部变量时(因为你不需要它们,或者你把私有事物建模为属性),或者当作者不关心时。 或者没有费心写下隐含的IEFE 。 其次,我很好奇模块模式如何处理同一类型的多个对象? ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。