01: /*
02: * @(#)_threadPool.java 1.2 04/12/06
03: *
04: * Copyright (c) 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.multithread;
10:
11: import pnuts.lang.Context;
12: import pnuts.lang.PnutsFunction;
13:
14: /*
15: * function threadPool(max)
16: * function threadPool(max, min)
17: * function threadPool(max, min, keepalive)
18: */
19: public class _threadPool extends PnutsFunction {
20: private final static long DEFAULT_KEEPALIVE = 1000;
21:
22: public _threadPool() {
23: super ("threadPool");
24: }
25:
26: public boolean defined(int nargs) {
27: return nargs == 1 || nargs == 2 || nargs == 3;
28: }
29:
30: protected Object exec(Object[] args, Context context) {
31: int nargs = args.length;
32: int max, min = 1;
33: long keepalive = DEFAULT_KEEPALIVE;
34: switch (nargs) {
35: case 3:
36: keepalive = ((Number) args[2]).longValue();
37: case 2:
38: min = ((Integer) args[1]).intValue();
39: case 1:
40: max = ((Integer) args[0]).intValue();
41: break;
42: default:
43: undefined(args, context);
44: return null;
45: }
46: return new ThreadPool(max, min, keepalive);
47: }
48:
49: public String toString() {
50: return "function threadPool( max {, min {, keepalive }} )";
51: }
52: }
|