0

How can I set maximum stack size?

I use jEdit to search with regular expression in rather big file (73 kb) and it fails with StackOverflowException.

I tried to set -Xss40m but it seems to be initial stack size and after some time it fails with following exception

11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0: Exception in thread "AWT-EventQueue-0"
11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0: java.lang.OutOfMemoryError: unable to create new native thread
11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0:  at java.lang.Thread.start0(Native Method)
11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0:  at java.lang.Thread.start(Unknown Source)
11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0:  at java.awt.EventQueue.initDispatchThread(Unknown Source)
11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0:  at java.awt.EventDispatchThread.run(Unknown Source)

I would appreciate if you explain me why OutOfMemory is thrown and also how to set max stack size.

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
  • possible duplicate of [Java: Unable to create new native thread](http://stackoverflow.com/questions/5253072/java-unable-to-create-new-native-thread) – Enno Shioji Aug 15 '11 at 08:51
  • StackOverflowException generally indicates that you are using recursion and either you haven't added an exit case, or a method is accidentally calling itself. – Goibniu Aug 15 '11 at 09:25
  • Is the file 73 kB (a rather small file) or is the regular expression 73 kB (a very expensive regex)? – Peter Lawrey Aug 15 '11 at 09:42
  • regex is small, file is 73 kb. May be I have bad regular expression (^\s*(\d+)([^0-9]|\n)+\1) but there was a great recursive depth – michael nesterenko Aug 15 '11 at 12:32

1 Answers1

0

Perhaps you should set the heap memory size as so:

java -Xms 512m -Xmx 1024m

adarshr
  • 61,315
  • 23
  • 138
  • 167