javax.ejb.Schedule Java Examples
The following examples show how to use
javax.ejb.Schedule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StockPublisher.java From blog-tutorials with MIT License | 6 votes |
@Schedule(second = "*/2", minute = "*", hour = "*", persistent = false) public void sendStockInformation() { TextMessage message; try (Connection connection = jmsFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(jmsQueue)) { JsonObject stockInformation = Json.createObjectBuilder() .add("stockCode", stockCodes[ThreadLocalRandom.current().nextInt(stockCodes.length)]) .add("price", ThreadLocalRandom.current().nextDouble(1.0, 150.0)) .add("timestamp", Instant.now().toEpochMilli()).build(); message = session.createTextMessage(); message.setText(stockInformation.toString()); producer.send(message); } catch (JMSException e) { e.printStackTrace(); } }
Example #2
Source File: AutomaticSellerService.java From packt-java-ee-7-code-samples with GNU General Public License v2.0 | 6 votes |
@Schedule(hour = "*", minute = "*", second = "*/30", persistent = false) public void automaticCustomer() { final Optional<Seat> seatOptional = findFreeSeat(); if (!seatOptional.isPresent()) { cancelTimers(); logger.info("Scheduler gone!"); return; // No more seats } final Seat seat = seatOptional.get(); theatreBox.buyTicket(seat.getId()); logger.info("Somebody just booked seat number " + seat.getId()); }
Example #3
Source File: StarterService.java From javaee7-websocket with MIT License | 6 votes |
@Schedule(second="*/3", minute="*",hour="*", persistent=false) public void play() { for (Map.Entry<String,TennisMatch> match : matches.entrySet()){ TennisMatch m = match.getValue(); if (m.isFinished()){ //add a timer to restart a match after 20 secondes m.reset(); } //Handle point if (random.nextInt(2) == 1){ m.playerOneScores(); } else { m.playerTwoScores(); } MatchEndpoint.send(new MatchMessage(m), match.getKey()); //if there is a winner, send result and reset the game if (m.isFinished()){ MatchEndpoint.sendBetMessages(m.playerWithHighestSets(), match.getKey(), true); } } }
Example #4
Source File: AutomaticSellerService.java From packt-java-ee-7-code-samples with GNU General Public License v2.0 | 6 votes |
/** * @throws NoSuchSeatException * if this is throw here, then this is a programming error */ @Schedule(hour = "*", minute = "*/1", persistent = false) public void automaticCustomer() throws NoSuchSeatException { final Optional<Seat> seatOptional = findFreeSeat(); if (!seatOptional.isPresent()) { cancelTimers(); logger.info("Scheduler gone!"); return; // No more seats } final Seat seat = seatOptional.get(); try { theatreBox.buyTicket(seat.getId()); } catch (SeatBookedException e) { // do nothing, user booked this seat in the meantime } logger.info("Somebody just booked seat number " + seat.getId()); }
Example #5
Source File: AutomaticSellerService.java From packt-java-ee-7-code-samples with GNU General Public License v2.0 | 6 votes |
/** * @throws NoSuchSeatException * if this is throw here, then this is a programming error */ @Schedule(hour = "*", minute = "*/1", persistent = false) public void automaticCustomer() throws NoSuchSeatException { final Optional<Seat> seatOptional = findFreeSeat(); if (!seatOptional.isPresent()) { cancelTimers(); logger.info("Scheduler gone!"); return; // No more seats } final Seat seat = seatOptional.get(); try { theatreBox.buyTicket(seat.getId()); } catch (SeatBookedException e) { // do nothing, user booked this seat in the meantime } logger.info("Somebody just booked seat number " + seat.getId()); }
Example #6
Source File: FarmerBrown.java From tomee with Apache License 2.0 | 5 votes |
@Schedules({ @Schedule(month = "5", dayOfMonth = "20-Last", minute = "0", hour = "8"), @Schedule(month = "6", dayOfMonth = "1-10", minute = "0", hour = "8") }) private void plantTheCorn() { // Dig out the planter!!! }
Example #7
Source File: ScheduleTest.java From tomee with Apache License 2.0 | 5 votes |
@Schedule(second = "2", minute = "*", hour = "*", info = "SubBeanBInfo") public void subBeanB(final javax.ejb.Timer timer) { synchronized (result) { assertEquals("SubBeanBInfo", timer.getInfo()); result.add(Call.TIMEOUT); } }
Example #8
Source File: ScheduleTest.java From tomee with Apache License 2.0 | 5 votes |
@Schedule(info = "badValue") public void subBeanC(final javax.ejb.Timer timer) { synchronized (result) { assertEquals("SubBeanCInfo", timer.getInfo()); result.add(Call.TIMEOUT); } }
Example #9
Source File: ScheduledTransactionNameInstrumentationTest.java From apm-agent-java with Apache License 2.0 | 5 votes |
@javax.ejb.Schedules({ @Schedule(minute = "5"), @Schedule(minute = "10") }) public void scheduledJava7Repeatable() { this.count.incrementAndGet(); }
Example #10
Source File: QueryExpirationBean.java From datawave with Apache License 2.0 | 5 votes |
/** * The cache eviction notifications are not working. Using an interceptor is not working either. This method will be invoked every 30 seconds by the timer * service and will evict entries that are idle or expired. */ @Schedule(hour = "*", minute = "*", second = "*/30", persistent = false) public void removeIdleOrExpired() { if (log.isDebugEnabled()) { log.debug("@Schedule - removeIdleOrExpired"); } long now = System.currentTimeMillis(); clearQueries(now); qlCache.clearQueryLogics(now, conf.getCallTimeInMS()); }
Example #11
Source File: StockExchangeNotifier.java From blog-tutorials with MIT License | 5 votes |
@Schedule(second = "*/5", minute = "*", hour = "*", persistent = false) public void sendNewStockExchangeInformation() { JsonObject stockInformation = Json.createObjectBuilder() .add("stock", "DKE-42") .add("price", new BigDecimal(ThreadLocalRandom.current().nextDouble(250.00)).setScale(2, RoundingMode.DOWN)) .build(); StockExchangeEndpoint.broadcastMessage(stockInformation); }
Example #12
Source File: ApiBudgetRefresher.java From blog-tutorials with MIT License | 5 votes |
@Schedule(minute = "*", hour = "*", persistent = false) public void updateApiBudget() { System.out.println("-- refreshing API budget for all users"); List<User> userList = entityManager.createQuery("SELECT u FROM User u", User.class).getResultList(); for (User user : userList) { user.setAmountOfApiCalls(0); } System.out.println("-- successfully refreshed API budget for all users"); }
Example #13
Source File: CachedResultsCleanupBean.java From datawave with Apache License 2.0 | 5 votes |
/** * Method that is invoked every 30 minutes from the Timer service. This will occur */ @Schedule(hour = "*", minute = "*/30", persistent = false) public void cleanup() { try (Connection con = ds.getConnection()) { String schema = con.getCatalog(); if (null == schema || "".equals(schema)) throw new RuntimeException("Unable to determine schema from connection"); try (Statement s = con.createStatement(); ResultSet rs = s.executeQuery(GET_TABLES_TO_REMOVE.replace("?", schema).replace("XYZ", Integer.toString(cachedResultsCleanupConfiguration.getDaysToLive())))) { while (rs.next()) { String objectName = CachedResultsParameters.validate(rs.getString(1)); // Drop the table String dropTable = "DROP TABLE " + objectName; try (Statement statement = con.createStatement()) { statement.execute(dropTable); } removeCrqRow(objectName); String viewName = CachedResultsParameters.validate(objectName.replaceFirst("t", "v")); // Drop the associated view String dropView = "DROP VIEW " + viewName; try (Statement statement = con.createStatement()) { statement.execute(dropView); } removeCrqRow(viewName); } } } catch (SQLException e) { log.error("Error cleaning up cached result objects: " + e.getMessage()); } }
Example #14
Source File: ScheduleTest.java From tomee with Apache License 2.0 | 5 votes |
@Schedule(second = "2", minute = "*", hour = "*", info = "SubBeanBInfo") public void subBeanA(final javax.ejb.Timer timer) { synchronized (result) { assertEquals("SubBeanAInfo", timer.getInfo()); result.add(Call.TIMEOUT); } }
Example #15
Source File: ConfigurationServiceBean.java From development with Apache License 2.0 | 5 votes |
@Schedule(minute = "*/10") @Lock(LockType.WRITE) public void refreshCache() { cache = new HashMap<>(); for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) { addToCache(configurationSetting); } }
Example #16
Source File: ConfigurationServiceBeanIT.java From development with Apache License 2.0 | 5 votes |
private List<Annotation> givenRefreshCacheAnnotations() { List<Annotation> result = new ArrayList<>(); Annotation schedule = mock(Annotation.class); doReturn(Schedule.class).when(schedule).annotationType(); doReturn("minute = \"*/10\"").when(schedule).toString(); result.add(schedule); result.add(createLockAnnotation("LockType.WRITE")); return result; }
Example #17
Source File: WatchMyDB.java From packt-java-ee-7-code-samples with GNU General Public License v2.0 | 5 votes |
@Schedule(dayOfWeek = "*", hour = "*", minute = "*", second = "*/30", year = "*", persistent = false) public void backgroundProcessing() { ModelControllerClient client = null; try { client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9990); final ModelNode operation = new ModelNode(); operation.get("operation").set("read-resource"); operation.get("include-runtime").set(true); final ModelNode address = operation.get("address"); address.add("subsystem", "datasources"); address.add("data-source", "ExampleDS"); address.add("statistics", "pool"); final ModelNode returnVal = client.execute(operation); final ModelNode node2 = returnVal.get("result"); final String stringActiveCount = node2.get("ActiveCount").asString(); if (stringActiveCount.equals("undefined")) { return; // Connection unused } int activeCount = Integer.parseInt(stringActiveCount); if (activeCount > 50) { alertAdministrator(); } } catch (Exception exc) { logger.log(Level.SEVERE, "Exception !", exc); } finally { safeClose(client); } }
Example #18
Source File: AutomaticSellerService.java From packt-java-ee-7-code-samples with GNU General Public License v2.0 | 5 votes |
@Schedule(hour = "*", minute = "*", second = "*/30", persistent = false) public void automaticCustomer() { final Seat seat = findFreeSeat(); if (seat == null) { cancelTimers(); logger.info("Scheduler gone!"); return; // No more seats } theatreBox.buyTicket(seat.getId()); logger.info("Somebody just booked seat number " + seat.getId()); }
Example #19
Source File: FinancialPeriodExpiredTask.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * This method is scheduled to run everyday at midnight and get all expired {@link FinancialPeriod} to mark them as * expired */ @Schedule(persistent = false, info = "Everyday at midnight") public void markAsExpired() { final List<FinancialPeriod> periods = this.financialPeriodRepository.findByClosedOrderByIdentificationAsc(false); periods.stream() .filter(period -> LocalDate.now().compareTo(period.getEnd()) > 0) .forEach(period -> { period.setExpired(true); this.financialPeriodRepository.saveAndFlush(period); }); }
Example #20
Source File: SampleDataManager.java From tomee with Apache License 2.0 | 5 votes |
@Schedule(second = "0", minute = "30", hour = "*", persistent = false) private void cleanData() { LOGGER.info("Cleaning data"); deleteAll(); createSomeData(); LOGGER.info("Data reset"); }
Example #21
Source File: FireObserver.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
@Schedule(hour="*",minute="*",second="*/5") public void fireEvent(){ ObservedData data = new ObservedData(); data.setaString("Hello "+aNumber); data.setaNumber(aNumber++); event.fire(data); LOG.info("event fired!!"); }
Example #22
Source File: MainBean.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
@Schedule(second = "0/10", minute = "*", hour = "*") public void fixText() { // Get a instance of the Statefull bean. if (null == statefullTalker) { statefullTalker = (StatefullBean) context .lookup("java:module/StatefullBean"); } // Set the state of the Statefull bean. String text = "Hello " + counter++; LOG.info("Fix text " + text); statefullTalker.setText(text); }
Example #23
Source File: MainBean.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
@Schedule(second = "5/10", minute = "*", hour = "*") public void say() { // Uses the Statefull bean and release it. if (null != statefullTalker) { statefullTalker.sayText(); statefullTalker = null; } }
Example #24
Source File: FinancialPeriodExpiredTask.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * This method is scheduled to run everyday at midnight and get all expired {@link FinancialPeriod} to mark them as * expired */ @Schedule(persistent = false, info = "Everyday at midnight") public void markAsExpired() { final List<FinancialPeriod> periods = this.financialPeriodRepository.findByClosedOrderByIdentificationAsc(false); periods.stream() .filter(period -> LocalDate.now().compareTo(period.getEnd()) > 0) .forEach(period -> { period.setExpired(true); this.financialPeriodRepository.saveAndFlush(period); }); }
Example #25
Source File: FarmerBrown.java From tomee with Apache License 2.0 | 5 votes |
@Schedules({ @Schedule(month = "9", dayOfMonth = "20-Last", minute = "0", hour = "8"), @Schedule(month = "10", dayOfMonth = "1-10", minute = "0", hour = "8") }) private void harvestTheCorn() { // Dig out the combine!!! }
Example #26
Source File: MDS.java From fido2 with GNU Lesser General Public License v2.1 | 5 votes |
@Schedule(hour = "3") @Lock(LockType.WRITE) private void refresh() { List<MDSService> newList = new ArrayList<>(); for (MDSService service : mdsList) { try { service.refresh(); newList.add(service); } catch (Exception e) { // if there's an exception, it won't get added to the new list } } mdsList = newList; }
Example #27
Source File: TimedMethodScheduledBean.java From metrics-cdi with Apache License 2.0 | 4 votes |
@Timed(name = "schedule") @Schedule(hour = "*", minute = "*", second = "*", persistent = false) public void scheduledMethod() { counter.count(); }
Example #28
Source File: CountedMethodScheduledBean.java From metrics-cdi with Apache License 2.0 | 4 votes |
@Counted(name = "count", monotonic = true) @Schedule(hour = "*", minute = "*", second = "*", persistent = false) public void scheduledMethod() { counter.count(); }
Example #29
Source File: Notifier.java From tomee with Apache License 2.0 | 4 votes |
@Schedule(second = "*", minute = "*", hour = "*") public void sendHour() { dateEvent.fire(new Date()); }
Example #30
Source File: MeteredMethodScheduledBean.java From metrics-cdi with Apache License 2.0 | 4 votes |
@Metered(name = "meter") @Schedule(hour = "*", minute = "*", second = "*", persistent = false) public void scheduledMethod() { counter.count(); }