Weblogic Server 11g上的自定义线程 [英] Custom Thread on Weblogic Server 11g

查看:187
本文介绍了Weblogic Server 11g上的自定义线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的weblogic服务器上需要一个自定义的threda;由于必须使用3d库,因此无法使用TimerEJB或Delayed MDB.

I need a custom threda on my weblogic server; I cannot use TimerEJB or Delayed MDB since I have to use a 3d library.

我知道不建议在应用程序服务器上使用自定义线程;这里是一篇相关的文章(4岁):为什么生成线程不鼓励在Java EE容器中使用它?

I know that custom threads on application server are discouraged; here a related post (4 years old): Why is spawning threads in Java EE container discouraged?

还是不鼓励吗?我可以使用ExecutorService还是Quartz?还是我只需要考虑commonj和工人经理?

Is it still discouraged? Can I use ExecutorService or Quartz? Or I have to consider only commonj and worker manager?

推荐答案

在Weblogic 11g(EJB3.0)上,建议不要创建自己的线程执行器"(另请参见

On Weblogic 11g (EJB3.0) is dicouraged to create "own thread executor" (see also Java EE specification and multi threading) you should use:

  • TimerService

示例:

MyEjb {
   @Stateless
   public class TimerBean implements TimerRemote {

    @Resource
    TimerService service;

    @Override
    public void startTimer() {
        Timer timer = service.createTimer(1000,  1000, null);
        System.out.println("Timers set");
    }

    @Timeout
    public void handleTimeout(Timer timer) {
        System.out.println("Handle timeout event here...");
    }
}

  • 延迟的MDB
  • WorkManager
    • Delayed MDB
    • WorkManager
    • **如果无法使用Deleyed MDB或TimerService,则需要使用Work Manager **.

      **If you cannot use Deleyed MDB or TimerService you need to work with Work Manager **.

      Weblogic和Websphere是CommonJ( JSR 237 Timer&符合WorkManager);换句话说,他们使用公共界面与工作经理一起工作;在weblogic中,工作管理者可以调节线程(Servlet,EJB,MDB,...,自定义线程)的生命周期.

      Weblogic and Websphere are CommonJ (JSR 237 Timer & WorkManager) compliant; in other words they use a common interface to work with work manager; in weblogic, work managers regulate the life cycle of threads (Servlet, EJB, MDB,..., custom thread).

      恕我直言,不要使用ExecutorService,因为它不受weblogic的控制:如果停止应用程序(而非服务器),则weblogic控制下的线程将停止,其他线程不应终止;我遇到了这个问题.

      IMHO do not use ExecutorService since is not under the control of weblogic: if you stop the application (not the server) the threads under weblogic control will stop, the other threads should not terminate; I experienced this problem.

      WebLogic Server中的WorkManager功能本质上是动态的,它根据传入请求的数量自动调整线程池大小,以最大程度地提高吞吐量. 要使用 WorkManager ,您可以通过commonj界面或MBean访问.

      The WorkManager feature in WebLogic Server is dynamic in nature, based on the number of incoming requests the thread pool size automatically re-sizes to maximize the throughput. To work with WorkManager you can access through commonj interface or MBean.

      示例:

      InitialContext ic = new InitialContext();
      commonj.work.WorkManager wm = (WorkManager);
      ic.lookup(‘java:comp/env/wm/default’); // default work manager
      

      春天

      例如,spring有一种简单的方法将其自己的TaskExecutor附加到comonj worker manager:

      Spring

      For instance spring has an easy way to attach its own TaskExecutor to comonj worker manager:

      <bean id="workManager" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
              <property name="workManagerName" value="java:comp/env/wm/default" />
          </bean>
      

      石英

      Quartz在应用服务器上运行,并且在春季使用可以使用工作管理器

      Quartz

      Quartz works on application servers and with spring they can use work manager

      JEE7引入了批处理( JSR 352 ). Java Platform API的批处理应用程序(批处理)为批处理应用程序提供了编程模型,并为计划和执行作业提供了运行时.

      JEE7 introduces Batch (JSR 352). The Batch Applications for the Java Platform API (Batch) provides a programming model for batch applications and a runtime for scheduling and executing jobs.

      执行人服务

      根据Java规范:

      Java EE 7平台中的另一个新功能是Batch API,它提供了一个 批处理应用程序的编程模型和调度的运行时 和执行作业,以及并发实用程序API,该API提供了 通过托管执行器服务实现异步功能, 托管的定期执行人.

      Also new in the Java EE 7 platform is the Batch API, which provides a programming model for batch applications and a runtime for scheduling and executing jobs, and the Concurrency Utilities API, which provides asynchronous capabilities by means of managed executor service, managed scheduled executor.

      在JEE7执行器服务中,ManagedExecutorServiceManagedThreadFactory进行了扩展.

      In JEE7 Executor Service has been extended with ManagedExecutorService and ManagedThreadFactory.

      示例:

         javax.naming.InitialContext ctx = new InitialContext();
         ManagedExecutorService mes = (ManagedExecutorService)
             ctx.lookup("java:comp/env/concurrent/ThreadPool");
      
         // Create a set of tasks to perform the account retrieval.
         ArrayList<Callable<MyObject>> retrieverTasks = new ArrayList<Callable<MyObject>>();
         retrieverTasks.add(new MyCallable());
      

      结论:Weblogic

      请参见 http://www.oracle.com/technetwork/java/stricts-142267.html

      这篇关于Weblogic Server 11g上的自定义线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆