8

When I run PowerShell in a remote session (etsn {servername}), I sometimes can't seem to run Java processes, even the most simple:

[chi-queuing]: PS C:\temp> java -cp .\hello.jar Hello
Error occurred during initialization of VM
Could not reserve enough space for object heap

Hello.jar is an "Hello, world!" application that should just print "Hello" to standard output.

So, the question is, is there something special about running processes on the other side of a PowerShell session? Is there something special about how the Java VM works that might not allow treatment like this? The memory is allocated on the remote computer, right? Here is a readout on the physical memory available:

[chi-queuing]: PS C:\temp> $mem = Get-wmiobject -class Win32_OperatingSystem
[chi-queuing]: PS C:\temp> $mem.FreePhysicalMemory
1013000

But, when I remote desktop to the server and ask the OS how much free memory there is, it says 270 MB physical memory free. Let me know what you think!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lmat - Reinstate Monica
  • 7,289
  • 6
  • 48
  • 62

3 Answers3

11

According to this: http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx

MaxMemoryPerShellMB Specifies the maximum amount of memory allocated per shell, including the shell's child processes. The default is 150 MB.

Increase Max Memory Per Shell MB

winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="1000"}' 
Community
  • 1
  • 1
mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • I'll go ahead and mark this as answer until it is proven wrong, but it looks about right...although I can't imagine JVM taking more than 150 MB for a simple program... – lmat - Reinstate Monica Jan 21 '11 at 14:09
  • 2
    The command line to increase the limit to 1000 MB (which worked for me): winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="1000"}' – bart Apr 17 '12 at 23:46
  • 1
    For PowerShell v3 or later you'll need to run this command as well to increase the RAM quota: Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 3000 – EvilPettingZu42 Jul 22 '13 at 23:12
  • Thanks. Worked for me on Win2008 Servers. It seemed odd that this wasn't a problem with our Win2012R2 servers. It's because those have this property set as 1024 by default it seems. – Quickmute Mar 14 '16 at 17:07
  • Is this setting done on remote server or from local (initiating) server? – Dilshad Abduwali Feb 20 '20 at 02:24
0

I have a different answer to share with you guys. I found myself in the same situation and increasing memory min/max for Java.exe or using winrm did NOT solve my issue.

I compared two servers: one working and one not working.

I used this link https://technet.microsoft.com/en-us/library/ff520073%28v=ws.10%29.aspx to check my Windows Management Foundation wich is needed to run WINRS and also remote powershell.

the result: Both servers running Windows Server 2008 R2. One server running WMF 2.0, one running WMF 3.0.

To my surprise, the server running 2.0 was working and the one running 3.0 was NOT!

My solution: I upgraded the 3.0 WMF to 4.0!

lmat - Reinstate Monica
  • 7,289
  • 6
  • 48
  • 62
  • I doubt this was the OP's original problem based on when the OP had his problem, but it's useful nonetheless! – lmat - Reinstate Monica Apr 07 '15 at 18:35
  • 1
    I realize this is not answer to the original question but wanted to share this because there a little hits on google about this. There is an official hotfix from Microsoft that acknowledges this: http://support.microsoft.com/en-us/kb/2842230 – Christian Glebbeek Apr 08 '15 at 08:31
0

Just a fyi: we suffered the same symptoms, and had an endless investigation based on the other two answers. The actual solution for us was changing jdk1.8.0_31 to jdk1.8.0_51.

hurjup
  • 23
  • 5