“java -server”和“java -client”之间的真正区别?

本文翻译自:Real differences between “java -server” and “java -client”?

Is there any real practical difference between "java -server" and "java -client"? “java -server”和“java -client”之间有什么实际的区别吗?

All I can find on Sun's site is a vague 我在Sun的网站上找到的所有内容都是模糊的

"-server starts slower but should run faster". “ - 服务器启动速度较慢,但​​应该运行得更快”。

What are the real differences? 有什么真正的区别? (Using JDK 1.6.0_07 currently.) (目前使用JDK 1.6.0_07。)


#1楼

参考:https://stackoom.com/question/per/java-server-和-java-client-之间的真正区别


#2楼

The most visible immediate difference in older versions of Java would be the memory allocated to a -client as opposed to a -server application. 旧版Java中最明显的直接差异是分配给-client而不是-server应用程序的内存。 For instance, on my Linux system, I get: 例如,在我的Linux系统上,我得到:

$ java -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'
uintx AdaptivePermSizeWeight               = 20               {product}
uintx ErgoHeapSizeLimit                    = 0                {product}
uintx InitialHeapSize                     := 66328448         {product}
uintx LargePageHeapSizeThreshold           = 134217728        {product}
uintx MaxHeapSize                         := 1063256064       {product}
uintx MaxPermSize                          = 67108864         {pd product}
uintx PermSize                             = 16777216         {pd product}
java version "1.6.0_24"

as it defaults to -server , but with the -client option I get: 因为它默认为-server ,但是使用-client选项我得到:

$ java -client -XX:+PrintFlagsFinal -version 2>&1 | grep -i -E 'heapsize|permsize|version'
uintx AdaptivePermSizeWeight               = 20               {product}
uintx ErgoHeapSizeLimit                    = 0                {product}
uintx InitialHeapSize                     := 16777216         {product}
uintx LargePageHeapSizeThreshold           = 134217728        {product}
uintx MaxHeapSize                         := 268435456        {product}
uintx MaxPermSize                          = 67108864         {pd product}
uintx PermSize                             = 12582912         {pd product}
java version "1.6.0_24"

so with -server most of the memory limits and initial allocations are much higher for this java version. 所以使用-server对于这个java版本,大多数内存限制和初始分配要高得多。

These values can change for different combinations of architecture, operating systems and jvm versions however. 但是,这些值可以针对体系结构,操作系统和jvm版本的不同组合进行更改。 Recent versions of the jvm have removed flags and re-moved many of the distinctions between server and client. jvm的最新版本删除了标志并重新移动了服务器和客户端之间的许多区别。

Remember too that you can see all the details of a running jvm using jvisualvm . jvisualvm记住,你可以使用jvisualvm查看正在运行的jvm所有细节。 This is useful if you have users who or modules which set JAVA_OPTS or use scripts which change command line options. 如果您有用户或模块​​设置JAVA_OPTS或使用更改命令行选项的脚本,这将非常有用。 This will also let you monitor, in real time, heap and permgen space usage along with lots of other stats. 这还可以让您实时监控permgen空间使用情况以及许多其他统计信息。


#3楼

Oracle's online documentation provides some information for Java SE 7. Oracle的在线文档提供了Java SE 7的一些信息。

On the java – the Java application launcher page for Windows, the -client option is ignored in a 64-bit JDK: Java( Windows 的Java应用程序启动器页面)上,在64位JDK中忽略-client选项:

Select the Java HotSpot Client VM. 选择Java HotSpot Client VM。 A 64-bit capable jdk currently ignores this option and instead uses the Java HotSpot Server VM. 具有64位功能的jdk当前忽略此选项,而是使用Java HotSpot Server VM。

However (to make things interesting), under -server it states: 但是(使事情变得有趣),下-server它指出:

Select the Java HotSpot Server VM. 选择Java HotSpot Server VM。 On a 64-bit capable jdk only the Java HotSpot Server VM is supported so the -server option is implicit. 在支持64位的jdk上,仅支持Java HotSpot Server VM,因此-server选项是隐式的。 This is subject to change in a future release. 这可能会在将来的版本中发生变化。

The Server-Class Machine Detection page gives information on which VM is selected by OS and architecture. 服务器级机器检测”页面提供有关OS和体系结构选择的VM的信息。

I don't know how much of this applies to JDK 6. 我不知道这对JDK 6有多大帮助。


#4楼

Last time I had a look at this, (and admittedly it was a while back) the biggest difference I noticed was in the garbage collection. 上次我看过这个,(并且不可否认它已经有一段时间了)我注意到的最大区别在于垃圾收集。

IIRC: IIRC:

  • The server heap VM has a differnt number of generations than the Client VM, and a different garbage collection algorithm. 服务器堆VM具有与客户端VM不同的代数,以及不同的垃圾收集算法。 This may not be true anymore 这可能不再适用
  • The server VM will allocate memory and not release it to the OS 服务器VM将分配内存,而不是将其释放到操作系统
  • The server VM will use more sophisticated optimisation algorithms, and hence have bigger time and memory requirements for optimisation 服务器VM将使用更复杂的优化算法,因此对优化有更大的时间和内存要求

If you can compare two java VMs, one client, one server using the jvisualvm tool, you should see a difference in the frequency and effect of the garbage collection, as well as in the number of generations. 如果您可以比较两个Java VM,一个客户端,一个使用jvisualvm工具的服务器,您应该看到垃圾收集的频率和效果以及代数的差异。

I had a pair of screenshots that showed the difference really well, but I can't reproduce as I have a 64 bit JVM which only implements the server VM. 我有一对屏幕截图显示差异非常好,但我无法重现,因为我有一个64位JVM只实现了服务器VM。 (And I can't be bothered to download and wrangle the 32 bit version on my system as well.) (而且我也不会在我的系统上下载和纠缠32位版本。)

This doesn't seem to be the case anymore, having tried running some code on windows with both server and client VMs, I seem to get the same generation model for both... 这似乎不再是这种情况,尝试在服务器和客户端虚拟机的Windows上运行一些代码,我似乎得到两个相同的生成模型...


#5楼

I've not noticed any difference in startup time between the 2, but clocked a very minimal improvement in application performance with "-server" (Solaris server, everyone using SunRays to run the app). 我没有发现2之间的启动时间有任何差异,但是使用“-server”(Solaris服务器,每个人都使用SunRays来运行应用程序),应用程序性能的改进非常小。 That was under 1.5. 那是在1.5以下。


#6楼

IIRC the server VM does more hotspot optimizations at startup so it runs faster but takes a little longer to start and uses more memory. IIRC服务器VM在启动时执行更多热点优化,因此运行速度更快,但需要更长时间才能启动并使用更多内存。 The client VM defers most of the optimization to allow faster startup. 客户端VM推迟大部分优化以允许更快的启动。

Edit to add: Here's some info from Sun, it's not very specific but will give you some ideas. 编辑添加: 这是来自Sun 的一些信息 ,它不是非常具体,但会给你一些想法。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值