當前位置: 首頁>>代碼示例>>Java>>正文


Java Schedule類代碼示例

本文整理匯總了Java中javax.ejb.Schedule的典型用法代碼示例。如果您正苦於以下問題:Java Schedule類的具體用法?Java Schedule怎麽用?Java Schedule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Schedule類屬於javax.ejb包,在下文中一共展示了Schedule類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: runTasks

import javax.ejb.Schedule; //導入依賴的package包/類
@Schedule(minute = "*/1", hour = "*", persistent = false)
public void runTasks() {
    if (!taskRunner.isBusy()) {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Run tasks started.");
        }
        taskRunner.runTasks();
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Run tasks finished.");
        }

        if (taskAppService.getDeleteEnabled()) {
            deleteFinishedTasks();
        }

        if (taskAppService.getTimeoutEnabled()) {
            interruptTasks();
        }
    }

}
 
開發者ID:jmd-stuff,項目名稱:task-app,代碼行數:22,代碼來源:RunTimer.java

示例2: automaticCustomer

import javax.ejb.Schedule; //導入依賴的package包/類
/**
 * @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());
}
 
開發者ID:packt-wildfly,項目名稱:packt-java-ee-7-code-samples,代碼行數:25,代碼來源:AutomaticSellerService.java

示例3: automaticCustomer

import javax.ejb.Schedule; //導入依賴的package包/類
@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());
}
 
開發者ID:packt-wildfly,項目名稱:packt-java-ee-7-code-samples,代碼行數:17,代碼來源:AutomaticSellerService.java

示例4: scheduledMoveItemsOfDeadSystems

import javax.ejb.Schedule; //導入依賴的package包/類
@Schedule(minute = "*", hour = "*", second = "*/15", persistent = false)
private void scheduledMoveItemsOfDeadSystems() {
    if (isMaster()) {
        LOG.info("Checking for queue items of dead systems in cluster (this is the cluster's master: ID="+SystemIdentifier.getIdentifier()+")");
        List<System> deadSystems = getSystemDao().getAllDeadWithQueueItems(getSystemDeadSeconds());
        if (deadSystems != null && deadSystems.size() > 0) {
            List<System> aliveSystems =  getSystemDao().getAllAlive(getSystemDeadSeconds());
            for (System deadSystem : deadSystems) {
                Integer sourceId = deadSystem.getSystemId();
                Integer targetId = aliveSystems.get(ThreadLocalRandom.current().nextInt(aliveSystems.size())).getSystemId();
                LOG.info("Moving dangling queue items from source ID=" + sourceId + " to target ID=" + targetId);
                getSendQueueItemDao().moveItems(sourceId, targetId);
            }
            LOG.info("Finished moving dangling queue items");
        }
    }
}
 
開發者ID:weweave,項目名稱:tubewarder,代碼行數:18,代碼來源:AliveStatusUpdater.java

示例5: cleanup

import javax.ejb.Schedule; //導入依賴的package包/類
/**
 * Cleans up held {@link Subscription}s and {@link Mail}
 **/
@Schedule(minute="*/15", hour="*")
public void cleanup()
{
    log.log(Level.FINE,"Starting cleanup");
    log.log(Level.FINE,"em is {0}", this.em);
	try
	{
		if(!isRunning)
		{
			isRunning = true;
			this.cleanupHeldSubscriptions();
			this.cleanupHeldMail();
		}
		else
		{
			log.warning("Attempted to start cleanup while one is already running; skipping cleanup.");				
		}
	}
	finally 
	{
		isRunning = false;
	}
}
 
開發者ID:voodoodyne,項目名稱:subetha,代碼行數:27,代碼來源:CleanupBean.java

示例6: play

import javax.ejb.Schedule; //導入依賴的package包/類
@Schedule(second="*/2", minute="*",hour="*", persistent=false)
public void play() {

	Set<byte[]> matches = jedis.smembers(jedisKey.getBytes());

    try {
        for (Iterator<byte[]> it = matches.iterator(); it.hasNext();) {
            TennisMatch m = (TennisMatch) deserialize(it.next());

            logger.info("Get from cache Key: " + m.getKey());
            MatchEndpoint.send(new MatchMessage(m), m.getKey());
            //if there is a winner, send result and reset the game
            if (m.isFinished()) {
                MatchEndpoint.sendBetMessages(m.playerWithHighestSets(), m.getKey(), true);
            }
        }
    }catch (Exception ex){
        logger.severe("Error with Cache " + ex.getCause());
        ex.printStackTrace();
    }
    Long nbMatches = jedis.scard(jedisKey.getBytes());
    logger.info("Number of matches: " + nbMatches);

}
 
開發者ID:mgreau,項目名稱:docker4dev-tennistour-app,代碼行數:25,代碼來源:StarterService.java

示例7: refresh

import javax.ejb.Schedule; //導入依賴的package包/類
/**
 * Let's schedule all remote updates for every 5 minutes.
 * WARNING!!!
 * You must keep persistent=false otherwise the timer
 * will be added to the DB each time the service is redeployed or the server is
 * restarted.  This will cause the method to be invoked N times at the timeout where
 * N is the number of restarts + deployments.
 * WARNING!!!
 * 
*/
@Override
@Schedule(second="0", minute="*/5", hour="*", persistent=false)
public void refresh() {
	KeyManagerProxy kmProxy = keyManagerProxyProvider.get();
	if(kmProxy != null) {
		try {
			List<Remote> remotes=kmProxy.remotes();
			remoteLookup.processRemotes(remotes);
			//Now iterate each remote type and get the remote layout  for that type.
			for(Remote remote:remotes){
				String remoteName=remote.getName();
				logger.debug(" Going to retrieve remote layout for: {} ",remoteName);
				List<RemoteLayout> layout=kmProxy.getRemoteLayout(remoteName);
				remoteLayoutLookup.processRemoteLayout(remoteName,layout);
			}
			lastSuccessfulRefresh = new Date();
		} catch(IllegalArgumentException e) {
			logger.error(e.getMessage());
		}
	} 
	else {
		logger.warn("KeyManagerProxy is null couldn't process keys");
	}
}
 
開發者ID:Comcast,項目名稱:cats,代碼行數:35,代碼來源:KeyManagerImpl.java

示例8: run

import javax.ejb.Schedule; //導入依賴的package包/類
@Schedule( second = "0", minute = "*/1", hour = "*", persistent = false )
public void run()
{
    logger.trace( "run" );
    List< Host > hosts = service.getEnabledHosts();
    for ( Host h : hosts )
    {
        /*
         * Enclose this in a large try/catch to prevent single host
         * exception from preventing reboot detection for remainder of
         * devices.
         */
        try
        {
            SettopSnmpUptimeRequestHandler handler = new SettopSnmpUptimeRequestHandler( h.getMacAddress(),
                    h.getIpAddress(), h.getEcm() );
            Long uptime = handler.retrieveUptime();
            logger.info( "{} = {}", h, uptime );
            service.processUptime( h, uptime, handler.getRebootDetectionStatus() );
        }
        catch ( Exception e )
        {
            logger.warn( "Unknown Exception Caught processing hosts", e );
        }
    }
}
 
開發者ID:Comcast,項目名稱:cats,代碼行數:27,代碼來源:RebootProcessingEngine.java

示例9: checkSystemStatus

import javax.ejb.Schedule; //導入依賴的package包/類
@Schedule(second = "0", minute = "*", hour = "*")
public void checkSystemStatus() {
	try {
		List<SystemStatusEO> listSystems = systemStatusService.getAllSystemStatus();
		LOG.info("Check status started, " + listSystems.size() + " systems to check");

		for (SystemStatusEO system : listSystems) {
			AbstractSystem content = SystemStatusFactory.getSystemStatusObject(system);
			boolean changed = content.executeCheck();
			LOG.info("Check of system " + system.getName() + ", changed = " + changed);
			if (changed) {
				system.setContent(content.marshal());
				systemStatusService.save(system);
				broadcastSystemStatusChanged(system, content.getReadableStatus(system));
			}
		}

	} catch (FablabException ex) {
		java.util.logging.Logger.getLogger(SystemChecker.class.getName()).log(Level.SEVERE, null, ex);
	}
}
 
開發者ID:romainGuiet,項目名稱:fablab-web,代碼行數:22,代碼來源:SystemChecker.java

示例10: run

import javax.ejb.Schedule; //導入依賴的package包/類
@PostConstruct
@Schedule(hour = "*/1", minute = "0", second = "0", persistent = false)
public void run() {
    List<Tarea> lista = tareasFacadeLocal.findAll();
    for (Tarea tarea : lista) {
        if (!tarea.getEstado().equals("VENCIDO")) {
            Calendar fechainicio = Calendar.getInstance();
            Calendar fechafinal = Calendar.getInstance();
            Calendar nowDate = Calendar.getInstance();
            fechainicio.setTime(tarea.getFechaInicio());
            fechafinal.setTime(tarea.getFechaFinalizacion());
            tarea.setEstado("POR INICIAR");
            if (fechainicio.before(nowDate)) {
                tarea.setEstado("ACTIVO");
            }
            if (fechafinal.before(nowDate)) {
                tarea.setEstado("VENCIDO");
            }
        }
    }
}
 
開發者ID:ivanbanos,項目名稱:inversionesgit,代碼行數:22,代碼來源:TimerCheckoutTareasEstado.java

示例11: removeOldSessions

import javax.ejb.Schedule; //導入依賴的package包/類
/**
 * Removes outdated sessions from the system
 */
@Schedule(second = "0", minute = "0", hour = "0", persistent = false)
public void removeOldSessions() {
	long startTime = System.currentTimeMillis();
	long numberOfSessions = 0;
	List<SessionEntity> sessions = this.sessionDao.getAll(SessionEntity.class);
	if (sessions != null) {
		for (SessionEntity session : sessions) {
			if (session != null) {
				Integer maxAgeInSeconds = this.settingBean.getIntegerSettingValue(SettingBean.SETTING_LONG_AUTH_SESSION_MAXAGE);
				long ageInSeconds = (System.currentTimeMillis() - session.getCreationTimestamp().getTime()) / 1000;
				if (ageInSeconds >= maxAgeInSeconds) {
					numberOfSessions++;
					this.getLogger().warning(
							"Session " + session.getKey() + " for " + session.getBundesbruder().getUserName()
									+ " is too old and cannot be used anymore - it will be removed");
					this.sessionDao.remove(session);
				}
			}
		}
	}
	this.getLogger().info("Removed " + numberOfSessions + " old session(s) in " + (System.currentTimeMillis() - startTime) + " ms");
}
 
開發者ID:RomanKreisel,項目名稱:Faktotum,代碼行數:26,代碼來源:AuthenticationBean.java

示例12: play

import javax.ejb.Schedule; //導入依賴的package包/類
@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);
    	}
	}
}
 
開發者ID:mgreau,項目名稱:javaee7-websocket,代碼行數:22,代碼來源:StarterService.java

示例13: updateLegacyWarnings

import javax.ejb.Schedule; //導入依賴的package包/類
/**
 * Called every 5 minutes to update the legacy MSI warnings
 */
@Schedule(persistent=false, second="13", minute="*/5", hour="*", dayOfWeek="*", year="*")
public void updateLegacyWarnings() {
    
    List<MsiDto> warnings = getActiveWarnings();
    log.info("Fetched " + warnings.size() + " legacy MSI warnings");
    
    for (MsiDto msi : warnings) {
        // Either create a new MSI or update an existing
        Message msg = messageService.findByMessageSeriesId(
                msi.getMessageId(), 
                msi.getCreated().toGregorianCalendar().get(Calendar.YEAR), 
                msi.getOrganisation());
        
        if (msg == null) {
            // Create a new message
            createNewNavwarnMessage(msi);
        } else {
            // TODO
        }   
    }
}
 
開發者ID:dma-enav,項目名稱:EnavShore,代碼行數:25,代碼來源:LegacyMsiService.java

示例14: refreshCache

import javax.ejb.Schedule; //導入依賴的package包/類
@Schedule(minute = "*/10")
@Lock(LockType.WRITE)
public void refreshCache() {
    cache = new HashMap<>();
    for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) {
        addToCache(configurationSetting);
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:9,代碼來源:ConfigurationServiceBean.java

示例15: givenRefreshCacheAnnotations

import javax.ejb.Schedule; //導入依賴的package包/類
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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:11,代碼來源:ConfigurationServiceBeanIT.java


注:本文中的javax.ejb.Schedule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。