List of usage examples for javax.management.timer Timer ONE_SECOND
long ONE_SECOND
To view the source code for javax.management.timer Timer ONE_SECOND.
Click Source Link
From source file:diplomawork.model.ViewForDiagram.java
@Override public void run() { while (this != null) { Float price = (GetDataFormYahoo.getPriceValue() != null) ? GetDataFormYahoo.getPriceValue().floatValue() : 1;//from w w w. ja va 2s . c om timeSeries.add(new Second(new Date(System.currentTimeMillis())), price); synchronized (this) { try { System.out.println("Name" + this.getName() + " waiting"); this.wait(Timer.ONE_SECOND * 5); } catch (InterruptedException ex) { Logger.getLogger(ViewForDiagram.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:playground.pieter.singapore.demand.InputDataCollection.java
private void loadHouseholdsAndPersons() { inputLog.info("Loading persons and households"); households = new HashMap<>(); persons = new HashMap<>(); String synthHouseholdIdField = diverseScriptProperties.getProperty("synthHouseholdId"); String carAvailabilityField = diverseScriptProperties.getProperty("carAvailability"); String homeFacilityIdField = diverseScriptProperties.getProperty("homeFacilityId"); String householdTableNameField = diverseScriptProperties.getProperty("householdTableName"); String householdSelectorTableNameField = diverseScriptProperties.getProperty("householdSelectorTableName"); String householdSelectorField = diverseScriptProperties.getProperty("householdSelectorField"); String personTableNameField = diverseScriptProperties.getProperty("personTableName"); String paxIdField = diverseScriptProperties.getProperty("paxId"); String foreignerField = diverseScriptProperties.getProperty("foreigner"); String carLicenseHolderField = diverseScriptProperties.getProperty("carLicenseHolder"); String ageField = diverseScriptProperties.getProperty("age"); String sexField = diverseScriptProperties.getProperty("sex"); String incomePaxField = diverseScriptProperties.getProperty("incomePax"); String modeSuggestionField = diverseScriptProperties.getProperty("modeSuggestion"); String incomeHouseholdField = diverseScriptProperties.getProperty("incomeHousehold"); String occupField = diverseScriptProperties.getProperty("occup"); String chainField = diverseScriptProperties.getProperty("chain"); String chainTypeField = diverseScriptProperties.getProperty("chainType"); String mainActStartField = diverseScriptProperties.getProperty("mainActStart"); String mainActDurField = diverseScriptProperties.getProperty("mainActDur"); String mainActTypeField = diverseScriptProperties.getProperty("mainActType"); int householdLoadLimit = Integer.parseInt(diverseScriptProperties.getProperty("householdLoadLimit")); Date startDate = new Date(); int counter = 0; ResultSet rs;//from ww w.ja va 2 s.c o m try { // sample random household ids without replacement // rs = dba.executeQuery(String.format("SELECT max(%s) FROM %s;", // synthHouseholdIdField, householdTableNameField)); // rs.next(); // int[] hhids = Sample.sampleMfromN(householdLoadLimitField, // rs.getInt(1)); // // // if (householdLoadLimitField > 1000000) { // rs = dba.executeQuery(String.format( // "SELECT DISTINCT %s, %s, %s FROM %s LIMIT %d;", // synthHouseholdIdField, homeFacilityIdField, // carAvailabilityField, householdTableNameField, // householdLoadLimitField)); // } else { // String hhidsToLoad = "" + hhids[0]; // for (int i = 1; i < hhids.length; i++) { // hhidsToLoad = hhidsToLoad + "," + hhids[i]; // } // rs = dba.executeQuery(String.format( // "SELECT DISTINCT %s, %s, %s FROM %s WHERE %s IN(%s);", // synthHouseholdIdField, homeFacilityIdField, // carAvailabilityField, householdTableNameField, // synthHouseholdIdField, hhidsToLoad)); rs = dba.executeQuery(String.format("SELECT count(*) as num FROM %s WHERE %s = 1;", householdSelectorTableNameField, householdSelectorField)); rs.next(); int householdCount = rs.getInt("num"); rs = dba.executeQuery(String.format( "SELECT hhs.%s, hhs.%s, hhs.%s FROM %s hhs,%s sel WHERE hhs.%s = sel.%s and %s = 1;", synthHouseholdIdField, homeFacilityIdField, carAvailabilityField, householdTableNameField, householdSelectorTableNameField, synthHouseholdIdField, synthHouseholdIdField, householdSelectorField)); // } while (rs.next()) { if (counter >= householdLoadLimit) break; int synthHouseholdId = rs.getInt(synthHouseholdIdField); int carAvailability = rs.getInt(carAvailabilityField); String homeFacilityId = "home_" + rs.getInt(homeFacilityIdField); HouseholdSG currentHousehold = new HouseholdSG(synthHouseholdId, carAvailability, homeFacilityId); households.put(synthHouseholdId, currentHousehold); ResultSet rspax = dba.executeQuery(String.format("SELECT * FROM %s WHERE %s = %d", personTableNameField, synthHouseholdIdField, synthHouseholdId)); while (rspax.next()) { String modeSuggestion = rspax.getString(modeSuggestionField); if ((modeSuggestion.equals("not_assigned") || modeSuggestion.equals("notravel"))) continue; String chainType = rspax.getString(chainTypeField); if (chainType == null) continue; // generate half mixed mode users if (modeSuggestion.equals("ptmix") && Math.random() > 0.5) continue; int paxId = rspax.getInt(paxIdField); String foreigner = rspax.getString(foreignerField); boolean carLicenseHolder = rspax.getInt(carLicenseHolderField) > 0; String chain = rspax.getString(chainField); int age = 0; if (rspax.getString(ageField).equals("age65_up")) age = 70; else age = Integer.parseInt(new StringBuilder(rspax.getString(ageField)).substring(3, 5)); String sex = rspax.getString(sexField); String occup = rspax.getString(occupField); int income = Integer.parseInt(rspax.getString(incomePaxField)); int incomeHousehold = rspax.getInt(incomeHouseholdField); String mainActType = rspax.getString(mainActTypeField); double mainActStart = Math.max(rspax.getDouble(mainActStartField), 0); double mainActDur = rspax.getDouble(mainActDurField); //skip if this guy is not meant to be realised PaxSG newPax = new PaxSG(paxId, foreigner, currentHousehold, carLicenseHolder, age, sex, income, occup, chain, chainType, mainActStart, mainActDur, mainActType, modeSuggestion); newPax.household.incomeHousehold = incomeHousehold; newPax.bizActFrequencies = assignSecondaryActFrequencies("b", newPax); newPax.leisureActFrequencies = assignSecondaryActFrequencies("l", newPax); currentHousehold.pax.add(newPax); this.persons.put(paxId, newPax); // timer info } if ((counter % 10000) == 0) { Date currDate = new Date(); long timePastLong = currDate.getTime() - startDate.getTime(); double timePastSec = (double) timePastLong / (double) Timer.ONE_SECOND; int agentsToGo = householdCount - counter; double agentsPerSecond = (double) counter / timePastSec; long timeToGo = (long) ((double) agentsToGo / agentsPerSecond); inputLog.info(String.format( "%6d of %8d households done in %.3f seconds at %.3f hhs/sec, %s sec to go.", counter, householdCount, timePastSec, agentsPerSecond, timeToGo)); } counter++; } } catch (SQLException | NoConnectionException e) { e.printStackTrace(); } inputLog.info("DONE: Loading persons and households"); }