Subversion Repositories XServices

Rev

Rev 102 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 102 Rev 185
Line 26... Line 26...
26
/**
26
/**
27
 * @author Brian Rosenberger, bru(at)brutex.de
27
 * @author Brian Rosenberger, bru(at)brutex.de
28
 *
28
 *
29
 */
29
 */
Line -... Line 30...
-
 
30
 
-
 
31
public class CacheExecutorService implements ServletContextListener {
-
 
32
	static final String EXECUTOR_NAME = "CACHE_EXECUTOR";
Line -... Line 33...
-
 
33
	private ExecutorService executor;
-
 
34
 
-
 
35
	public void contextInitialized(ServletContextEvent arg0) {
-
 
36
		ServletContext context = arg0.getServletContext();
-
 
37
		int nr_executors = 5;
-
 
38
		ThreadFactory daemonFactory = new DaemonThreadFactory();
-
 
39
		try {
-
 
40
			nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count"));
-
 
41
		} catch (NumberFormatException localNumberFormatException) {
-
 
42
		}
-
 
43
		if (nr_executors <= 1)
-
 
44
			this.executor = Executors.newSingleThreadExecutor(daemonFactory);
-
 
45
		else {
-
 
46
			this.executor = Executors.newFixedThreadPool(nr_executors, daemonFactory);
-
 
47
		}
Line 30... Line -...
30
 
-
 
31
 
-
 
32
 
-
 
33
public class CacheExecutorService
-
 
34
  implements ServletContextListener
-
 
35
{
-
 
36
  static final String EXECUTOR_NAME = "CACHE_EXECUTOR";
-
 
37
  private ExecutorService executor;
-
 
38
 
-
 
39
  public void contextInitialized(ServletContextEvent arg0)
-
 
40
  {
-
 
41
    ServletContext context = arg0.getServletContext();
-
 
42
    int nr_executors = 5;
-
 
43
    ThreadFactory daemonFactory = new DaemonThreadFactory();
-
 
44
    try {
-
 
45
      nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count"));
-
 
46
    } catch (NumberFormatException localNumberFormatException) {
-
 
47
    }
-
 
48
    if (nr_executors <= 1)
-
 
49
      this.executor = Executors.newSingleThreadExecutor(daemonFactory);
-
 
50
    else {
-
 
51
      this.executor = Executors.newFixedThreadPool(nr_executors, daemonFactory);
-
 
52
    }
-
 
53
    context.setAttribute("CACHE_EXECUTOR", this.executor);
48
		context.setAttribute("CACHE_EXECUTOR", this.executor);
54
  }
49
	}
55
 
50
 
56
  public void contextDestroyed(ServletContextEvent arg0) {
51
	public void contextDestroyed(ServletContextEvent arg0) {
57
    ServletContext context = arg0.getServletContext();
52
		ServletContext context = arg0.getServletContext();
58
    this.executor.shutdownNow();
53
		this.executor.shutdownNow();