闲置时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?
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
最满意答案
该模块有点搞砸了。 它应该遵循这种模式:
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.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
我创建了一个名为augment的库,它将模块模式与原型继承相结合。 例如,你可以使用augment实现你的Anagram “类”如下: var augment = require("augment"); var Anagram = module.exports = augment(Object, function () { this.constructor = function (original) { this.original = original.toLowerCase(); ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
构造函数和原型是实现类和实例的合理方式之一。 它们并不完全对应于该模型,因此您通常需要选择特定的方案或帮助方法来实现原型方面的类。 ( JS中的类的一些背景 ) 模块模式通常用于命名空间,其中您将有一个实例充当存储来分组相关的功能和对象。 这是一个不同的用例,从什么原型是有益的。 他们不是真的相互竞争; 你可以非常高兴地一起使用(例如在模块中放置一个构造函数,并说出new MyNamespace.MyModule.MyClass(arguments) )。 Constructor-functions and ...
-
模块模式不是类模式。 你不能简单地假装你现在有JavaScript的课程。 至于继承,如果你真的需要继承东西,你应该通过构造函数创建一个对象并使用原型继承,尽管它有时候执行起来会比较慢。 至于创建子模块很简单 MODULE.submodule = (function(){ // another module stuff that can even reference MODULE return { submodule: 'property' } })(); 现在,就古典意义上的子类化而言, ...
-
Javascript模块模式使用Prototype创建多个实例(Javascript Module Pattern create multiple instances using Prototype)[2022-01-18]
函数本身的属性就像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, ...
-
揭示模块/原型模式(Revealing Module / Prototype Pattern)[2022-02-06]
虽然这段代码按预期工作,但最近我发了一篇文章,如果你有多个实例,这个模式会占用大量内存 您在第一个代码段中显示的代码是单例模块,没有“多个实例”。 这完全没问题。 只有标题为Module pattern - Multiple instances的东西Module pattern - Multiple instances小提琴中的Module pattern - Multiple instances在实例化大量对象时会遇到内存缺陷 。 但是,请注意,这不是“模块模式”,而是“工厂模式”。 现在我想知道使用Re ... -
模块模式的提示(Tips for the Module Pattern)[2022-01-30]
我的假设是只使用后一种方法,因为由于闭包能够使用私有变量..? 我对么? 是。 如果你需要私有变量。 第一种方法不使用闭包,因此位于全局内存范围内,不能拥有私有成员。 但请注意,即使在第二个示例中, s变量也是不必要的全局变量。 那么为什么CSS Tricks和其他人使用第一种方法作为例子,当它似乎没有任何真正的目的? 为简单起见。 当你没有局部变量时(因为你不需要它们,或者你把私有事物建模为属性),或者当作者不关心时。 或者没有费心写下隐含的IEFE 。 其次,我很好奇模块模式如何处理同一类型的多个对象? ...