当前位置: 首页>>代码示例>>Java>>正文


Java ManagedThreadFactory类代码示例

本文整理汇总了Java中javax.enterprise.concurrent.ManagedThreadFactory的典型用法代码示例。如果您正苦于以下问题:Java ManagedThreadFactory类的具体用法?Java ManagedThreadFactory怎么用?Java ManagedThreadFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ManagedThreadFactory类属于javax.enterprise.concurrent包,在下文中一共展示了ManagedThreadFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lookupManagedThreadFactory

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
private ManagedThreadFactory lookupManagedThreadFactory(HystrixThreadPoolKey threadPoolKey) {
    if (context == null) {
        return null;
    }

    String name = "java:concurrent/" + threadPoolKey.name();

    Object thing = null;
    try {
        thing = context.lookup(name);
    } catch (NamingException e) {
        LOGGER.warn("Unable to lookup managed thread factory.", e);
    }

    if (thing instanceof ManagedThreadFactory) {
        return (ManagedThreadFactory) thing;
    } else if (thing == null) {
        LOGGER.warn("Unable to find a JSR 236 managed thread factory using {} in JDNI.", name);
        return null;
    } else {
        LOGGER.warn("Found thing is not a JSR 236 managed thread factory, it is a {} instead.", thing);
        return null;
    }
}
 
开发者ID:lreimer,项目名称:cloud-native-javaee,代码行数:25,代码来源:HystrixConcurrencyStrategyJsr236.java

示例2: testJNDILookup

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
/**
     * Test of run method, of class MyTask.
     * 
     * using JNDI lookup
     */
//    @Test
    public void testJNDILookup() {
        try {
            InitialContext ctx = new InitialContext();

//            ManagedExecutorService executor = (ManagedExecutorService) ctx.lookup("concurrent/myExecutor");
            ManagedThreadFactory myFactory = (ManagedThreadFactory) ctx.lookup("java:comp/DefaultManagedThreadFactory");
            assertNotNull(myFactory);
            Thread thread = myFactory.newThread(new MyTask(1));
            assertNotNull(thread);
            thread.start();
        } catch (NamingException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        }
    }
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:21,代码来源:MyTaskTest.java

示例3: createInstances

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@Override
public Model createInstances(Model createModel) throws ProcessingException, InvalidRequestException {
  
  try {
    ManagedThreadFactory threadFactory = (ManagedThreadFactory) new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
    CallOpenSDNcore callOpenSDNcore = new CallOpenSDNcore(createModel, this);
    Thread callOpenSDNcoreThread = threadFactory.newThread(callOpenSDNcore);
    callOpenSDNcoreThread.start();
  } catch (NamingException e) {
    LOGGER.log(Level.SEVERE, "REQUIRED VMs counldn't be created ", e);
  }
  
  
  Model returnModel = ModelFactory.createDefaultModel();
  ResIterator resIterator = createModel.listSubjectsWithProperty(Omn.isResourceOf);
  while(resIterator.hasNext()){
    Resource resource = resIterator.nextResource();
    Resource res = returnModel.createResource(resource.getURI());
    Property property = returnModel.createProperty(Omn_lifecycle.hasState.getNameSpace(), Omn_lifecycle.hasState.getLocalName());
    property.addProperty(RDF.type, OWL.FunctionalProperty);
    res.addProperty(property, Omn_lifecycle.Uncompleted);
  }
  
   return returnModel;
   
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:27,代码来源:ToscaAdapter.java

示例4: updateInstance

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@Override
@SuppressWarnings({ "PMD.GuardLogStatement", "PMD.GuardLogStatementJavaUtil" })
public Model updateInstance(final String instanceURI, final Model configureModel) {
  
  String confModel = MessageUtil.serializeModel(configureModel, IMessageBus.SERIALIZATION_TURTLE);
  System.out.println("Attenuator Configure model \n" + confModel);
  
  AttenuatorSetter attenuatorSeter = new AttenuatorSetter(this.attenuator, configureModel, this.getAdapterABox());
  
  try{
    ManagedThreadFactory managedThreadFactory = (ManagedThreadFactory) new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
    Thread attenuatorThread = managedThreadFactory.newThread(attenuatorSeter);
    attenuatorThread.start();
  } catch (NamingException e) {
    LOGGER.log(Level.SEVERE, "Thread couldn't be created ", e);
  }
  return this.parseToModel(instanceURI);
  
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:20,代码来源:AttenuatorAdapter.java

示例5: updateInstance

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@Override
@SuppressWarnings({ "PMD.GuardLogStatement", "PMD.GuardLogStatementJavaUtil" })
public Model updateInstance(final String instanceURI, final Model configureModel) {
  
  String confModel = MessageUtil.serializeModel(configureModel, IMessageBus.SERIALIZATION_TURTLE);
  System.out.println("ACS Configure model \n" + confModel);
  
  ACSclient acs_client = this.getInstanceByName(instanceURI);
  acs_client.parseConfigureModel(configureModel);
  
  try{
    ManagedThreadFactory managedThreadFactory = (ManagedThreadFactory) new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
    Thread acsThread = managedThreadFactory.newThread(acs_client);
    acsThread.start();
  } catch (NamingException e) {
    LOGGER.log(Level.SEVERE, "Thread couldn't be created ", e);
  }
  return this.parseToModel(acs_client);
  
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:21,代码来源:ACSclientAdapter.java

示例6: createInstance

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@Override
	public Model createInstance(String instanceURI, Model modelCreate)
			throws ProcessingException, InvalidRequestException {

		SshService sshService = new SshService(this, instanceURI);
		
		StmtIterator iter = modelCreate.listStatements();
    while(iter.hasNext()){
      sshService.updateProperty(iter.next());
    }
		instanceList.put(instanceURI, sshService);
		
		try {
      ManagedThreadFactory managedThreadFactory = (ManagedThreadFactory) new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
      Thread sshServiceThread = managedThreadFactory.newThread(sshService);
      sshServiceThread.start();
    } catch (NamingException e) {
      LOGGER.log(Level.SEVERE, "User accounts counldn't be created ", e);
    }
		
//		sshService.addSshAccess();
		return createResponse(sshService);
		
		
	}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:26,代码来源:SshServiceAdapter.java

示例7: createExecutorService

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
private ExecutorService createExecutorService() {
    final BlockingQueue<Runnable> blockingQueue;
    if (queue <= 0) {
        blockingQueue = new LinkedBlockingQueue<>();
    } else {
        blockingQueue = new ArrayBlockingQueue<>(queue);
    }

    ManagedThreadFactory managedThreadFactory;
    try {
        managedThreadFactory = "org.apache.openejb.threads.impl.ManagedThreadFactoryImpl".equals(threadFactory) ?
                new ManagedThreadFactoryImpl() :
                ThreadFactories.findThreadFactory(threadFactory);
    } catch (final Exception e) {
        Logger.getInstance(LogCategory.OPENEJB, ManagedExecutorServiceImplFactory.class).warning("Can't create configured thread factory: " + threadFactory, e);
        managedThreadFactory = new ManagedThreadFactoryImpl();
    }

    return new ThreadPoolExecutor(core, max, keepAlive.getTime(), keepAlive.getUnit(), blockingQueue, managedThreadFactory, CURejectHandler.INSTANCE);
}
 
开发者ID:apache,项目名称:tomee,代码行数:21,代码来源:ManagedExecutorServiceImplFactory.java

示例8: doCheck

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses, final ManagedThreadFactory tf) {
    assertNotNull(es);
    assertNotNull(ses);
    assertNotNull(tf);

    assertThat(es, instanceOf(ManagedExecutorServiceImpl.class));
    assertEquals(2, pool(es).getCorePoolSize());
    assertEquals(10, pool(es).getMaximumPoolSize());
    assertEquals(4, pool(es).getKeepAliveTime(TimeUnit.MINUTES));

    assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class));
    assertEquals(12, pool(ses).getCorePoolSize());

    assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class));
    assertEquals("custom-", Reflections.get(tf, "prefix"));
}
 
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:CustomInjectionTest.java

示例9: setUp

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    concurrencyStrategy = new HystrixConcurrencyStrategyJsr236();

    mtf = mock(ManagedThreadFactory.class);
    when(rule.getContext().lookup("java:concurrent/test")).thenReturn(mtf);
}
 
开发者ID:lreimer,项目名称:cloud-native-javaee,代码行数:8,代码来源:HystrixConcurrencyStrategyJsr236Test.java

示例10: processRequest

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
/**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet TestJNDIServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Getting ManagedThreadFactory using JNDI lookup</h1>");
            try {
                InitialContext ctx = new InitialContext();
                
                ManagedThreadFactory factory = (ManagedThreadFactory) ctx.lookup("java:comp/DefaultManagedThreadFactory");
//                ManagedExecutorService executor = (ManagedExecutorService) ctx.lookup("concurrent/myExecutor");
                out.println("Getting ManageableThread<br>");
                Thread thread = factory.newThread(new MyTask(2));
                out.println("Starting thread<br>");
                thread.start();
                out.println("Thread started<br><br>");
            } catch (NamingException ex) {
                Logger.getLogger(TestResourceServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
            out.println("all tasks submitted<br/><br/>");
            out.println("Check server.log for output from the task.");
            out.println("</body>");
            out.println("</html>");
        }
    }
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:41,代码来源:TestJNDIServlet.java

示例11: HelloWebSocketEndpoint

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
public HelloWebSocketEndpoint() {
    log.debug("new HelloWebSocketEndpoint()");
    try {
        InitialContext context = new InitialContext();
        managedThreadFactory = (ManagedThreadFactory) context.lookup("java:jboss/ee/concurrency/factory/default");
    } catch (NamingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:10,代码来源:HelloWebSocketEndpoint.java

示例12: createInstances

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@Override
public Model createInstances(Model newInstanceModel){
    LOGGER.log(Level.INFO, "OSCO-ADAPTER RECEIVED CREATE");
    try {
        ManagedThreadFactory threadFactory = (ManagedThreadFactory) new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
        CallOpenSDNcoreJson callOpenSDNcore = new CallOpenSDNcoreJson(newInstanceModel, this);
        callOpenSDNcore.addDatacenters(datacenters);
        callOpenSDNcore.addDatacenterConfig(client.getConfig());
        Thread callOpenSDNcoreThread = threadFactory.newThread(callOpenSDNcore);
        callOpenSDNcoreThread.start();
    } catch (NamingException e) {
        LOGGER.log(Level.SEVERE, "REQUIRED VMs counldn't be created ", e);
    }


    Model returnModel = ModelFactory.createDefaultModel();
    ResIterator resIterator = newInstanceModel.listSubjectsWithProperty(Omn.isResourceOf);
    while(resIterator.hasNext()){
        Resource resource = resIterator.nextResource();
        Resource res = returnModel.createResource(resource.getURI());
        Property property = returnModel.createProperty(Omn_lifecycle.hasState.getNameSpace(), Omn_lifecycle.hasState.getLocalName());
        property.addProperty(RDF.type, OWL.FunctionalProperty);
        res.addProperty(RDF.type, Omn.Resource);
        res.addProperty(property, Omn_lifecycle.Uncompleted);
    }

    return returnModel;

}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:30,代码来源:OSCOAdapter.java

示例13: init

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
public void init() {
	try {
           CheckForRessources ressourceCheckerThread = new CheckForRessources(adapterABox);
           ManagedThreadFactory threadFactory = (ManagedThreadFactory)new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
           Thread createVMThread = threadFactory.newThread((Runnable)ressourceCheckerThread);
           createVMThread.start();
       }
       catch (NamingException e) {
           e.printStackTrace();
       }


}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:14,代码来源:OpenBatonAdapter.java

示例14: startNSR

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
public void startNSR(Model createdInstances,String topologyUri){
	Property property = adapterABox.getModel().createProperty(Omn_lifecycle.hasState.getNameSpace(), Omn_lifecycle.hasState.getLocalName());
       property.addProperty(RDF.type, (RDFNode)OWL.FunctionalProperty);
       try {
       	Topology topology = (Topology) this.getInstanceList().get(topologyUri);
           CreateNSR createNsr = new CreateNSR(createdInstances, property, this.listener,topology);
           ManagedThreadFactory threadFactory = (ManagedThreadFactory)new InitialContext().lookup("java:jboss/ee/concurrency/factory/default");
           Thread createVMThread = threadFactory.newThread((Runnable)createNsr);
           createVMThread.start();
       }
       catch (NamingException e) {
           e.printStackTrace();
       }
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:15,代码来源:OpenBatonAdapter.java

示例15: startThread

import javax.enterprise.concurrent.ManagedThreadFactory; //导入依赖的package包/类
@SuppressWarnings("PMD.GuardLogStatementJavaUtil")
   private void startThread() {
final RPMCreator creator = new RPMCreator();
if (this.threadFactory == null) {
    Context context;
    try {
	context = new InitialContext();
	this.threadFactory = (ManagedThreadFactory) context.lookup(Motor.THREAD_FACTORY);
    } catch (final NamingException e) {
	Motor.LOGGER.log(Level.SEVERE, "Could not create managed thread factory: " + Motor.THREAD_FACTORY);
    }
}
this.thread = this.threadFactory.newThread(creator);
this.thread.start();
   }
 
开发者ID:FITeagle,项目名称:adapters,代码行数:16,代码来源:Motor.java


注:本文中的javax.enterprise.concurrent.ManagedThreadFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。