WebLogic 8 中长时间任务的处理

本文介绍如何在WebLogic中为耗时较长的请求配置专用执行队列,并提供WebLogic8的具体示例代码,同时说明WebLogic9中执行队列被WorkManager取代的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Web应用中,有些请求非常耗时,为避免其执行时间过长,干扰其他应用,通常的方式是给这些请求设置一个专用的执行队列。例如,web.xml中的下列配置将耗时很长的文件wls8.jsp配置一个专用执行队列:

  1.     <servlet>
  2.         <servlet-name>longtimeServlet</servlet-name>
  3.         <jsp-file>/wls8.jsp</jsp-file>
  4.         <init-param>
  5.             <param-name>wl-dispatch-policy</param-name>
  6.             <param-value>MyExecute Queue</param-value>
  7.         </init-param>
  8.     </servlet> 

这里执行队列名为“MyExecute Queue”,直接访问/wls8.jsp将通过“MyExecute Queue”执行,而不会通过默认的“weblogic.kernel.Default”执行队列,当“MyExecute Queue”满后,后续请求将会进入“MyExecute Queue”的等待队列中。注意:如果从其他请求重定向到wls8.jsp,则还是在原始线程中执行。

 

由于这些请求都非常耗时,而进入队列也只是暂缓执行而已,总归是会执行的。处于系统整体效率考虑,希望不要等待队列,无空闲线程时直接返回系统忙就可以了。但是,在WebLogic中,执行队列的最新等待队列就是256,所以需要通过编程来处理。

 

WebLogic 8示例如下,其中customQueue 是配置的执行线程名。

  1. <%@ page contentType="text/html;charset=GBK"%>
  2. <%@page import="javax.naming.Context"%>
  3. <%@page import="weblogic.management.MBeanHome"%>
  4. <%@page import="weblogic.management.runtime.ServerRuntimeMBean"%>
  5. <%@page import="weblogic.management.Helper"%>
  6. <%@page import="weblogic.management.runtime.ExecuteQueueRuntimeMBean"%>
  7. <%@page import="weblogic.jndi.Environment"%>
  8. <html>
  9. <body>
  10. <ol>
  11.     <%
  12.         String url = "t3://localhost:7001";
  13.         String serverName = "myserver";
  14.         String username = "weblogic";
  15.         String password = "weblogic";
  16.         String customQueue = "MyExecute Queue";
  17.         Environment env = new Environment();
  18.         env.setProviderUrl(url);
  19.         env.setSecurityPrincipal(username);
  20.         env.setSecurityCredentials(password);
  21.         //Setting the initial context            
  22.         Context ctx = env.getInitialContext();
  23.         //Retrieving the server-specific MBeanHome interface            
  24.         MBeanHome home = (MBeanHome) ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
  25.         ServerRuntimeMBean serverRuntimeMBean = (ServerRuntimeMBean) home
  26.                 .getRuntimeMBean(serverName, "ServerRuntime");
  27.         ExecuteQueueRuntimeMBean[] runtimeMBeans = serverRuntimeMBean
  28.                 .getExecuteQueueRuntimes();
  29.         for (int i = 0; i < runtimeMBeans.length; i++) {
  30.             ExecuteQueueRuntimeMBean runtime = runtimeMBeans[i];
  31.             out.println("<li><p>ExecuteQueue " + runtime.getName()
  32.                     + ".</p>TotalCount="
  33.                     + runtime.getExecuteThreadTotalCount()
  34.                     + ",CurrentIdleCount="
  35.                     + runtime.getExecuteThreadCurrentIdleCount());
  36.             if (runtime.getName().equals(customQueue)) {
  37.                 if (runtime.getExecuteThreadCurrentIdleCount() < 1) {
  38.                     out.println("System Busy.");
  39.                     return;
  40.                 }
  41.             }
  42.         }
  43.         response.flushBuffer();
  44.         //长时间操作,通过sleep来模拟
  45.         Thread.sleep(30000);
  46.     %>
  47. </ol>
  48. </body>
  49. </html>

在WebLogic 9中,执行队列的概念已经被Work Manger取代了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值