clojure icon indicating copy to clipboard operation
clojure copied to clipboard

increase agent stack size

Open dehubbed opened this issue 13 years ago • 0 comments

Per default newly created threads have a stack size of 8kb on Android/Dalvik which is a lot less than the usual 256-512 kB on a 'normal' JVM. This limit is easily hit when e.g. "eval"-ing moderately complex expressions.

In places where one is in control of creating new threads in one's own project one can easily use the Thread constructor that allows one to specify a stack size. However Clojure creates threads implicitly, e.g. for agents.

Changing createThreadFactory in clojure.lang.Agent fixes this:

private static ThreadFactory createThreadFactory(final String format, final AtomicLong threadPoolCounter) { return new ThreadFactory() { public Thread newThread(Runnable runnable) { return new Thread(Thread.currentThread().getThreadGroup(), runnable, String.format(format, threadPoolCounter.getAndIncrement()), 256 * 1204); } }; }

This could be amended to only explicitly set the stack size explicitly if the DalvikVM has been detected and leave it to the default otherwise.

dehubbed avatar Jun 30 '12 15:06 dehubbed