public static void main(String[] args) throws Exception { final Config config = Config.loadFromDisk("nexus-importer"); final HTTPCache http = HttpClient.createHttpCache(config); final XmlParser xmlParser = new XmlParser(); final BoneCPDataSource boneCp = config.createBoneCp(); XmlParser.debugXml = false; ObjectManager<NexusServerDto, ActorRef<NexusServer>> serverManager = new ObjectManager<>( "Nexus server", Collections.<NexusServerDto>emptySet(), new ObjectFactory<NexusServerDto, ActorRef<NexusServer>>() { public ActorRef<NexusServer> create(NexusServerDto server) { final NexusClient client = new NexusClient(http, server.url); String name = server.name; return ObjectUtil.threadedActor( name, config.nexusUpdateInterval, boneCp, "Nexus Server: " + name, new NexusServer(client, server, xmlParser)); } }); final AtomicBoolean shouldRun = new AtomicBoolean(true); config.addShutdownHook(currentThread(), shouldRun); while (shouldRun.get()) { try { List<NexusServerDto> newKeys; try (Connection c = boneCp.getConnection()) { newKeys = new NexusDao(c).selectServer(); } serverManager.update(newKeys); } catch (SQLException e) { e.printStackTrace(System.out); } synchronized (shouldRun) { shouldRun.wait(60 * 1000); } } serverManager.close(); }