1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.servlet.filters.threaddump;
16  
17  import com.liferay.portal.servlet.filters.BasePortalFilter;
18  import com.liferay.portal.util.PropsValues;
19  
20  import java.util.concurrent.Executors;
21  import java.util.concurrent.ScheduledExecutorService;
22  import java.util.concurrent.ScheduledFuture;
23  import java.util.concurrent.TimeUnit;
24  
25  import javax.servlet.FilterChain;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /**
30   * <a href="ThreadDumpFilter.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Shuyang Zhou
33   * @author Brian Wing Shun Chan
34   */
35  public class ThreadDumpFilter extends BasePortalFilter {
36  
37      protected void processFilter(
38              HttpServletRequest request, HttpServletResponse response,
39              FilterChain filterChain)
40          throws Exception {
41  
42          ScheduledFuture<?> scheduledFuture =
43              _scheduledExecutorService.schedule(
44                  _threadDumper, PropsValues.THREAD_DUMP_SPEED_THRESHOLD,
45                  TimeUnit.SECONDS);
46  
47          try {
48              processFilter(
49                  ThreadDumpFilter.class, request, response, filterChain);
50          }
51          finally {
52              scheduledFuture.cancel(true);
53          }
54      }
55  
56      private static int _MAX_THREAD_DUMPERS = 5;
57  
58      private static ScheduledExecutorService _scheduledExecutorService =
59          Executors.newScheduledThreadPool(_MAX_THREAD_DUMPERS);
60      private static ThreadDumper _threadDumper = new ThreadDumper();
61  
62  }