javax.ejb.Singleton.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中javax.ejb.Singleton.<init>()方法的一些代码示例,展示了Singleton.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Singleton.<init>()方法的具体详情如下:
包路径:javax.ejb.Singleton
类名称:Singleton
方法名:<init>

Singleton.<init>介绍

暂无

代码示例

代码示例来源:origin: javaee-samples/javaee7-samples

@Singleton
public class BeanMessage implements BeanMessageInterface {

  private String message = "";

  @Override
  public String getMessage() {
    return message;
  }

  @Override
  public void setMessage(String message) {
    this.message = message;
    System.out.println("BeanMessage: setMessage=" + this.message);
  }

  @Override
  public void appendMessage(String message) {
    this.message += message;
    System.out.println("BeanMessage: appendMessage=" + this.message);
  }

  @Override
  public String sayHello() {
    return "Hello from: " + this.getClass().getName() + "; " + System.identityHashCode(this);
  }

}

代码示例来源:origin: jersey/jersey

@Singleton
public class EjbReloaderService {

代码示例来源:origin: jersey/jersey

/**
 * Singleton EJB counter bean as a JAX-RS resource.
 * The bean is for one published as a standalone JAX-RS resource
 * and for two used to inject other EJB based JAX-RS resources.
 *
 * @author Jakub Podlesak (jakub.podlesak at oracle.com)
 */
@Singleton
@Path("counter")
public class EjbCounterResource {

  final AtomicInteger counter = new AtomicInteger();

  @Context UriInfo ui;

  @GET
  public int getCount() {
    return counter.incrementAndGet();
  }

  @Path("{ui}")
  @GET
  public String getUi() {
    return ui != null ? ui.getPath() : "UriInfo is null";
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * @author arungupta
 */
@Startup
@Singleton
public class MyTimerScheduleBean extends AbstractTimerBatch {
}

代码示例来源:origin: javaee-samples/javaee7-samples

@Startup
@Singleton
public class PingsListener {

  final List<Ping> pings = new CopyOnWriteArrayList<>();

  public void listen(@Observes Ping ping) {
    System.out.println("ping = " + ping);
    pings.add(ping);
  }

  public List<Ping> getPings() {
    return pings;
  }
}

代码示例来源:origin: jersey/jersey

/**
 * JAX-RS resource that keeps number of reloads.
 *
 * @author Jakub Podlesak (jakub.podlesak at oracle.com)
 */
@Provider
@Singleton
public class ContainerListener extends AbstractContainerLifecycleListener {

  @EJB EjbReloaderService reloader;

  @Override
  public void onStartup(final Container container) {
    reloader.setContainer(container);
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * @author Jacek Jackowiak
 */
@Startup
@Singleton
public class SchedulesTimerBean {

  @Inject
  Event<Ping> pingEvent;

  @Schedules({
      @Schedule(hour = "*", minute = "*", second = "*/5", info = "Every 5 second timer"),
      @Schedule(hour = "*", minute = "*", second = "*/10", info = "Every 10 second timer")
  })
  public void automaticallyScheduled(Timer timer) {
    pingEvent.fire(new Ping(timer.getInfo().toString()));
  }

}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * @author Arun Gupta
 */
@Startup
@Singleton
public class AutomaticTimerBean {

  @Resource
  SessionContext ctx;

  @Inject
  Event<Ping> pingEvent;

  @Schedule(hour = "*", minute = "*", second = "*/5", info = "Every 5 second timer")
  public void printDate() {
    Collection<Timer> timers = ctx.getTimerService().getAllTimers();
    for (Timer t : timers) {
      pingEvent.fire(new Ping(t.getInfo().toString()));
    }
  }

}

代码示例来源:origin: javaee-samples/javaee7-samples

@Singleton
public class BeanLeaf {

  private static final String MESSAGE_POST = "PostBeanLeaf";
  private static final String MESSAGE_HELLO = "HelloBeanLeaf";

  @EJB
  private BeanMessageInterface msg;

  @PostConstruct
  public void afterConstruct() {
    if (msg != null && !msg.getMessage().contains(MESSAGE_POST)) {
      msg.appendMessage(MESSAGE_POST);
    }
  }

  public String sayHello() {
    if (msg != null && !msg.getMessage().contains(MESSAGE_HELLO)) {
      msg.appendMessage(MESSAGE_HELLO);
    }

    return "Hello from: " + this.getClass().getName() + "; " + System.identityHashCode(this);
  }

}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * @author Jacek Jackowiak
 */
@Startup
@Singleton
public class MultipleScheduleTimerBean {

  @Inject
  Event<Ping> pingEvent;

  @Schedule(hour = "*", minute = "*", second = "*/5", info = "Every 5 second timer")
  public void fastAutomaticallyScheduled(Timer timer) {
    fireEvent(timer);
  }

  @Schedule(hour = "*", minute = "*", second = "*/10", info = "Every 10 second timer")
  public void slowlyAutomaticallyScheduled(Timer timer) {
    fireEvent(timer);
  }

  private void fireEvent(Timer timer) {
    pingEvent.fire(new Ping(timer.getInfo().toString()));
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * @author Arun Gupta
 */
@Startup
@Singleton
public class MySingletonBeanManagedConcurrency {

  volatile StringBuilder builder;

  @PostConstruct
  private void postConstruct() {
    builder = new StringBuilder();
    System.out.println("postConstruct");
  }

  public String readSomething() {
    return "current timestamp: " + new Date();
  }

  public String writeSomething(String something) {
    synchronized (builder) {
      builder.append(something);
    }
    return builder.toString() + " : " + new Date();
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

/**
 * @author Arun Gupta
 */
@Startup
@Singleton
public class MySingleton {
  StringBuilder builder;

  @PostConstruct
  private void postConstruct() {
    System.out.println("postConstruct");
    builder = new StringBuilder();
  }

  @Lock(LockType.READ)
  public String readSomething() {
    return "current timestamp: " + new Date();
  }

  @Lock(LockType.WRITE)
  public String writeSomething(String something) {
    builder.append(something);
    return builder.toString() + " : " + new Date();
  }
}

代码示例来源:origin: javaee-samples/javaee7-samples

@Singleton
public class ProgrammaticTimerBean {

代码示例来源:origin: javaee-samples/javaee7-samples

@Singleton
@Startup
public class BeanRoot implements BeanRootInterface {

代码示例来源:origin: camunda/camunda-bpm-platform

@Named("SingletonBeanDelegate")
@Singleton
public class SingletonBeanDelegate implements JavaDelegate {

 public void execute(DelegateExecution execution) throws Exception {
  execution.setVariable(SingletonBeanDelegate.class.getName(), true);
 }

}

代码示例来源:origin: hector-client/hector

@Singleton
  public static class AnEJB {
    @PersistenceContext(unitName = "homEE")
    private EntityManager em;

    // just for the tx context
    public void persist(Object o) {
      em.persist(o);
    }
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * A SingletonBean with a local business interface 
 * 
 * @author Daniel Meyer
 *
 */
@Singleton
@Local(BusinessInterface.class)
public class LocalSingletonBean implements BusinessInterface {

 public boolean doBusiness() {
  return true;
 }

}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * A SingletonBean with a remote business interface 
 * 
 * @author Daniel Meyer
 *
 */
@Singleton
@Remote(BusinessInterface.class)
public class RemoteSingletonBean implements BusinessInterface {

 public boolean doBusiness() {
  return true;
 }

}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * @author Tassilo Weidner
 */
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@ProcessApplication(deploymentDescriptors = {"deployment-descriptor-with-custom-filename.xml"})
@Local(ProcessApplicationInterface.class)
public class AnnotatedEjbPa extends EjbProcessApplication {

 @PostConstruct
 public void start() {
  deploy();
 }

 @PreDestroy
 public void stop() {
  undeploy();
 }

}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Custom {@link EjbProcessApplication} with PA lifecycle callbacks
 *
 * @author Daniel Meyer
 *
 */
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@ProcessApplication
@Local(ProcessApplicationInterface.class)
public class CustomEjbProcessApplication extends EjbProcessApplication {

 @PostDeploy
 public void postDeploy(ProcessEngine processEngine) {
  Assert.assertNotNull(processEngine);
 }

 @PreUndeploy
 public void preUnDeploy(ProcessEngine processEngine) {
  Assert.assertNotNull(processEngine);
 }

}

相关文章