diff options
author | Matthew Newhook <matthew@zeroc.com> | 2014-07-23 15:06:02 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2014-07-23 15:06:02 -0230 |
commit | 866f9ff17391176b836f9bb49f6da40c2c938441 (patch) | |
tree | 7366963294ef3356c7b887cd89af753988c21beb /java/demo | |
parent | adding ACM tests for Python/Ruby/PHP (diff) | |
download | ice-866f9ff17391176b836f9bb49f6da40c2c938441.tar.bz2 ice-866f9ff17391176b836f9bb49f6da40c2c938441.tar.xz ice-866f9ff17391176b836f9bb49f6da40c2c938441.zip |
ICE-4234 - Update Ice to use current Java threading constructs
- Use ScheduledThreadPoolDispatcher not IceUtilInternal.Timer.
- Use Ice timer in glacier2, Freeze impl.
- Align C++, C# with java changes.
- Database demo now supports mariadb.
Diffstat (limited to 'java/demo')
-rw-r--r-- | java/demo/Database/library/Glacier2SessionManagerI.java | 4 | ||||
-rw-r--r-- | java/demo/Database/library/README | 23 | ||||
-rw-r--r-- | java/demo/Database/library/ReapTask.java (renamed from java/demo/Database/library/ReapThread.java) | 66 | ||||
-rw-r--r-- | java/demo/Database/library/RunParser.java | 120 | ||||
-rw-r--r-- | java/demo/Database/library/Server.java | 17 | ||||
-rw-r--r-- | java/demo/Database/library/SessionFactoryI.java | 4 | ||||
-rw-r--r-- | java/demo/Database/library/config.server | 11 | ||||
-rw-r--r-- | java/demo/Freeze/casino/BetResolver.java | 41 | ||||
-rw-r--r-- | java/demo/Glacier2/voip/Server.java | 15 | ||||
-rw-r--r-- | java/demo/Ice/session/Client.java | 87 | ||||
-rw-r--r-- | java/demo/Ice/session/ReapTask.java | 69 | ||||
-rw-r--r-- | java/demo/Ice/session/ReapThread.java | 87 | ||||
-rw-r--r-- | java/demo/Ice/session/Server.java | 14 | ||||
-rw-r--r-- | java/demo/Ice/session/SessionFactoryI.java | 4 |
14 files changed, 233 insertions, 329 deletions
diff --git a/java/demo/Database/library/Glacier2SessionManagerI.java b/java/demo/Database/library/Glacier2SessionManagerI.java index 3d6ab50db88..e1632ba66f1 100644 --- a/java/demo/Database/library/Glacier2SessionManagerI.java +++ b/java/demo/Database/library/Glacier2SessionManagerI.java @@ -27,12 +27,12 @@ class Glacier2SessionManagerI extends Glacier2._SessionManagerDisp return proxy; } - Glacier2SessionManagerI(Ice.Logger logger, ReapThread reaper) + Glacier2SessionManagerI(Ice.Logger logger, ReapTask reaper) { _logger = logger; _reaper = reaper; } private Ice.Logger _logger; - private ReapThread _reaper; + private ReapTask _reaper; } diff --git a/java/demo/Database/library/README b/java/demo/Database/library/README index a690d4dc6a6..286a16008d7 100644 --- a/java/demo/Database/library/README +++ b/java/demo/Database/library/README @@ -1,8 +1,8 @@ MySQL JDBC Demo =============== -This demo shows how to implement an Ice server that uses mysql through -a JDBC API and demonstrates the following techniques: +This demo shows how to implement an Ice server that uses MariaDB or mysql +through a JDBC API and demonstrates the following techniques: - Mapping relational data to Ice objects, and in particular the conversion between Ice and JDBC types. @@ -15,15 +15,24 @@ a JDBC API and demonstrates the following techniques: Building the demo ----------------- -1. Install mysql if necessary. +1. Install mysql or MariaDB as necessary. -2. Download version 5.1.23 of the mysql JDBC connector here: +2. Download version 5.1.31 of the mysql JDBC connector here: http://dev.mysql.com/downloads/connector/j/5.1.html - After extracting the archive, add mysql-connector-java-5.1.23-bin.jar + After extracting the archive, add mysql-connector-java-5.1.31-bin.jar to your CLASSPATH. + Alternatively, for MariaDB Download version 1.1.7 of the MariaDB Client + Library for Java Applications here: + + https://downloads.mariadb.org/client-java/+releases/ + + After downloading the jar, add mariadb-java-client-1.1.7.jar to your + CLASSPATH. You must also edit config.server and change the JDBC.Url and + JDBC.DriverClassName to the MariaDB configurations. + 3. Create a database named "library" and grant privileges to a user. In the commands below, replace USER with the name you have chosen and PASSWORD with a suitable password: @@ -56,8 +65,8 @@ Building the demo NOTES: These instructions assume that the demo server runs on the same - host as the mysql server. If you intend to run the demo server on - a different host than the mysql server, you will need to revise + host as the database server. If you intend to run the demo server on + a different host than the database server, you will need to revise the mysql privileges as well as the JDBC URL in config.server. In order to get correct results when using multiple concurrent diff --git a/java/demo/Database/library/ReapThread.java b/java/demo/Database/library/ReapTask.java index a5b43dc135d..3ded348c1a6 100644 --- a/java/demo/Database/library/ReapThread.java +++ b/java/demo/Database/library/ReapTask.java @@ -9,7 +9,7 @@ import Demo.*; -class ReapThread extends Thread +class ReapTask implements Runnable { static class SessionProxyPair { @@ -32,7 +32,7 @@ class ReapThread extends Thread SessionI session; } - ReapThread(Ice.Logger logger, long timeout) + ReapTask(Ice.Logger logger, long timeout) { _logger = logger; _timeout = timeout; @@ -41,60 +41,43 @@ class ReapThread extends Thread synchronized public void run() { - while(!_terminated) + java.util.Iterator<SessionProxyPair> p = _sessions.iterator(); + while(p.hasNext()) { + SessionProxyPair s = p.next(); try { - wait((_timeout / 2) * 1000); - } - catch(InterruptedException e) - { - } - - if(!_terminated) - { - java.util.Iterator<SessionProxyPair> p = _sessions.iterator(); - while(p.hasNext()) + // + // Session destruction may take time in a + // real-world example. Therefore the current time + // is computed for each iteration. + // + if((System.currentTimeMillis() - s.session.timestamp()) > _timeout * 1000) { - SessionProxyPair s = p.next(); - try + _logger.trace("ReapTask", "The session " + + s.proxy.ice_getCommunicator().identityToString(s.proxy.ice_getIdentity()) + + " has timed out."); + if(s.proxy != null) { - // - // Session destruction may take time in a - // real-world example. Therefore the current time - // is computed for each iteration. - // - if((System.currentTimeMillis() - s.session.timestamp()) > _timeout * 1000) - { - _logger.trace("ReapThread", "The session " + - s.proxy.ice_getCommunicator().identityToString(s.proxy.ice_getIdentity()) + - " has timed out."); - if(s.proxy != null) - { - s.proxy.destroy(); - } - else - { - s.glacier2proxy.destroy(); - } - p.remove(); - } + s.proxy.destroy(); } - catch(Ice.ObjectNotExistException e) + else { - p.remove(); + s.glacier2proxy.destroy(); } + p.remove(); } } + catch(Ice.ObjectNotExistException e) + { + p.remove(); + } } } synchronized public void terminate() { - _terminated = true; - notify(); - // Destroy each of the sessions, releasing any resources they // may hold. This calls directly on the session, not via the // proxy since terminate() is called after the communicator is @@ -119,8 +102,7 @@ class ReapThread extends Thread _sessions.add(new SessionProxyPair(proxy, session)); } - private final long _timeout; // Seconds. + private final long _timeout; private Ice.Logger _logger; - private boolean _terminated = false; private java.util.List<SessionProxyPair> _sessions = new java.util.LinkedList<SessionProxyPair>(); } diff --git a/java/demo/Database/library/RunParser.java b/java/demo/Database/library/RunParser.java index 736dcb95267..691eda79a00 100644 --- a/java/demo/Database/library/RunParser.java +++ b/java/demo/Database/library/RunParser.java @@ -19,71 +19,21 @@ class RunParser public LibraryPrx getLibrary(); public void destroy(); public void refresh(); + public long getTimeout(); } - static private class SessionRefreshThread extends Thread - { - SessionRefreshThread(Ice.Logger logger, long timeout, SessionAdapter session) - { - _logger = logger; - _session = session; - _timeout = timeout; // seconds. - } - - synchronized public void - run() - { - while(!_terminated) - { - try - { - wait(_timeout * 1000); - } - catch(InterruptedException e) - { - } - if(!_terminated) - { - try - { - _session.refresh(); - } - catch(Ice.LocalException ex) - { - _logger.warning("SessionRefreshThread: " + ex); - _terminated = true; - } - } - } - } - - synchronized private void - terminate() - { - _terminated = true; - notify(); - } - - final private Ice.Logger _logger; - final private SessionAdapter _session; - final private long _timeout; - private boolean _terminated = false; - } - - static int - runParser(String appName, String[] args, Ice.Communicator communicator) - { + static SessionAdapter + createSession(String appName, Ice.Communicator communicator) { SessionAdapter session; final Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.uncheckedCast(communicator.getDefaultRouter()); - long timeout; if(router != null) { Glacier2.SessionPrx glacier2session = null; + long timeout; java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); while(true) { System.out.println("This demo accepts any user-id / password combination."); - try { String id; @@ -116,6 +66,7 @@ class RunParser ex.printStackTrace(); } } + final long to = timeout; final Glacier2SessionPrx sess = Glacier2SessionPrxHelper.uncheckedCast(glacier2session); session = new SessionAdapter() { @@ -145,6 +96,11 @@ class RunParser { sess.refresh(); } + + public long getTimeout() + { + return to; + } }; } else @@ -154,10 +110,11 @@ class RunParser if(factory == null) { System.err.println(appName + ": invalid object reference"); - return 1; + return null; } final SessionPrx sess = factory.create(); + final long timeout = factory.getSessionTimeout()/2; session = new SessionAdapter() { public LibraryPrx getLibrary() @@ -174,11 +131,44 @@ class RunParser { sess.refresh(); } + + public long getTimeout() + { + return timeout; + } }; - timeout = factory.getSessionTimeout()/2; } - SessionRefreshThread refresh = new SessionRefreshThread(communicator.getLogger(), timeout, session); - refresh.start(); + return session; + } + + static int + runParser(String appName, String[] args, final Ice.Communicator communicator) + { + final SessionAdapter session = createSession(appName, communicator); + if(session == null) + { + return 1; + } + + java.util.concurrent.ScheduledExecutorService executor = java.util.concurrent.Executors.newScheduledThreadPool(1); + executor.scheduleAtFixedRate(new Runnable() + { + public void + run() + { + try + { + session.refresh(); + } + catch(Ice.LocalException ex) + { + communicator.getLogger().warning("SessionRefreshThread: " + ex); + // Exceptions thrown from the executor task supress subsequent execution + // of the task. + throw ex; + } + } + }, session.getTimeout(), session.getTimeout(), java.util.concurrent.TimeUnit.SECONDS); LibraryPrx library = session.getLibrary(); @@ -196,19 +186,7 @@ class RunParser rc = parser.parse(); } - if(refresh != null) - { - refresh.terminate(); - try - { - refresh.join(); - } - catch(InterruptedException e) - { - } - refresh = null; - } - + executor.shutdown(); session.destroy(); return rc; diff --git a/java/demo/Database/library/Server.java b/java/demo/Database/library/Server.java index c5fb2f4f940..e1f7b6816a2 100644 --- a/java/demo/Database/library/Server.java +++ b/java/demo/Database/library/Server.java @@ -64,7 +64,7 @@ class Server extends Ice.Application try { - Class.forName("com.mysql.jdbc.Driver").newInstance(); + Class.forName(properties.getProperty("JDBC.DriverClassName")).newInstance(); } catch(Exception e) { @@ -92,9 +92,10 @@ class Server extends Ice.Application long timeout = properties.getPropertyAsIntWithDefault("SessionTimeout", 30); - ReapThread reaper = new ReapThread(logger, timeout); - reaper.start(); - + java.util.concurrent.ScheduledExecutorService executor = java.util.concurrent.Executors.newScheduledThreadPool(1); + ReapTask reaper = new ReapTask(logger, timeout); + executor.scheduleAtFixedRate(reaper, timeout/2, timeout/2, java.util.concurrent.TimeUnit.SECONDS); + // // Create an object adapter // @@ -116,14 +117,8 @@ class Server extends Ice.Application communicator().waitForShutdown(); defaultInterrupt(); + executor.shutdown(); reaper.terminate(); - try - { - reaper.join(); - } - catch(InterruptedException e) - { - } pool.destroy(); diff --git a/java/demo/Database/library/SessionFactoryI.java b/java/demo/Database/library/SessionFactoryI.java index bf954a89774..b3c3606719a 100644 --- a/java/demo/Database/library/SessionFactoryI.java +++ b/java/demo/Database/library/SessionFactoryI.java @@ -33,7 +33,7 @@ class SessionFactoryI extends _SessionFactoryDisp return _timeout; } - SessionFactoryI(Ice.Logger logger, ReapThread reaper, long timeout) + SessionFactoryI(Ice.Logger logger, ReapTask reaper, long timeout) { _logger = logger; _reaper = reaper; @@ -41,6 +41,6 @@ class SessionFactoryI extends _SessionFactoryDisp } private Ice.Logger _logger; - private ReapThread _reaper; + private ReapTask _reaper; private long _timeout; } diff --git a/java/demo/Database/library/config.server b/java/demo/Database/library/config.server index 3438cd2f142..b8a0555d661 100644 --- a/java/demo/Database/library/config.server +++ b/java/demo/Database/library/config.server @@ -6,7 +6,18 @@ SessionFactory.Endpoints=tcp -h localhost -p 10000:ssl -h localhost -p 10001 # JDBC configuration. JDBC.Username=USER JDBC.Password=PASSWORD + +# +# For mysql use the following configuration. +# JDBC.Url=jdbc:mysql://localhost/library +JDBC.DriverClassName=com.mysql.jdbc.Driver + +# +# For MariaDB use the following configuration. +# +#JDBC.Url=jdbc:mariadb://localhost/library +#JDBC.DriverClassName=org.mariadb.jdbc.Driver # The number of connections in the JDBC connection pool. This number # should be at least as big as the number of the threads in the server diff --git a/java/demo/Freeze/casino/BetResolver.java b/java/demo/Freeze/casino/BetResolver.java index dc23bcee41a..4e5238e1584 100644 --- a/java/demo/Freeze/casino/BetResolver.java +++ b/java/demo/Freeze/casino/BetResolver.java @@ -11,19 +11,14 @@ class BetResolver { BetResolver() { - // - // We create a little pool of timers - // - for(int i = 0; i < _timers.length; ++i) - { - _timers[i] = new java.util.Timer(); - } + // We want the executor to shutdown even if there are scheduled tasks. + _executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); } void add(final CasinoStore.PersistentBetPrx bet, long closeTime) { - java.util.TimerTask task = new java.util.TimerTask() + Runnable task = new Runnable() { public void run() @@ -46,38 +41,32 @@ class BetResolver } finally { - synchronized(BetResolver.this) - { - _betCount--; - } + _betCount.decrementAndGet(); } } }; - _timers[_random.nextInt(_timers.length)].schedule(task, new java.util.Date(closeTime)); + // closeTime is milliseconds from the epoch. Convert to relative time. + long now = new java.util.Date().getTime(); + _executor.schedule(task, closeTime - now, java.util.concurrent.TimeUnit.MILLISECONDS); - synchronized(this) - { - _betCount++; - } - } + _betCount.incrementAndGet(); + } void cancel() { - for(java.util.Timer timer : _timers) - { - timer.cancel(); - } + _executor.shutdown(); } - synchronized int + int getBetCount() { - return _betCount; + return _betCount.get(); } - private java.util.Timer[] _timers = new java.util.Timer[3]; + private java.util.concurrent.ScheduledThreadPoolExecutor _executor = + new java.util.concurrent.ScheduledThreadPoolExecutor(3); private java.util.Random _random = new java.util.Random(); - private int _betCount = 0; + private java.util.concurrent.atomic.AtomicInteger _betCount = new java.util.concurrent.atomic.AtomicInteger(); } diff --git a/java/demo/Glacier2/voip/Server.java b/java/demo/Glacier2/voip/Server.java index ec036f905a6..b1bff6b1968 100644 --- a/java/demo/Glacier2/voip/Server.java +++ b/java/demo/Glacier2/voip/Server.java @@ -28,7 +28,7 @@ import Voip._SessionDisp; public class Server extends Ice.Application { - private final ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1); + private final ScheduledThreadPoolExecutor _executor = new ScheduledThreadPoolExecutor(1); class SessionI extends _SessionDisp { @@ -42,7 +42,7 @@ public class Server extends Ice.Application public void simulateCall(int delay, Current current) { - timer.schedule(new Runnable() + _executor.schedule(new Runnable() { public void run() { @@ -107,7 +107,7 @@ public class Server extends Ice.Application final long sessionTimeout = 1202; final SessionI session = new SessionI(); final SessionPrx proxy = SessionPrxHelper.uncheckedCast(current.adapter.addWithUUID(session)); - timer.scheduleWithFixedDelay(new Runnable() + _executor.scheduleWithFixedDelay(new Runnable() { public void run() { @@ -124,7 +124,13 @@ public class Server extends Ice.Application return proxy; } }; - + + Server() + { + // We want the executor to shutdown even if there are scheduled tasks. + _executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); + } + public int run(String[] args) { @@ -139,6 +145,7 @@ public class Server extends Ice.Application adapter.add(new SessionManagerI(), communicator().stringToIdentity("VoipSessionManager")); adapter.activate(); communicator().waitForShutdown(); + _executor.shutdown(); return 0; } diff --git a/java/demo/Ice/session/Client.java b/java/demo/Ice/session/Client.java index 0b9bc151e23..060e7a20ddf 100644 --- a/java/demo/Ice/session/Client.java +++ b/java/demo/Ice/session/Client.java @@ -28,55 +28,6 @@ public class Client extends Ice.Application } } - static private class SessionRefreshThread extends Thread - { - SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session) - { - _logger = logger; - _session = session; - _timeout = timeout; - } - - synchronized public void - run() - { - while(!_terminated) - { - try - { - wait(_timeout); - } - catch(InterruptedException e) - { - } - if(!_terminated) - { - try - { - _session.refresh(); - } - catch(Ice.LocalException ex) - { - _logger.warning("SessionRefreshThread: " + ex); - _terminated = true; - } - } - } - } - - synchronized private void - terminate() - { - _terminated = true; - notify(); - } - - final private Ice.Logger _logger; - final private SessionPrx _session; - final private long _timeout; - private boolean _terminated = false; - } - private static void menu() { @@ -135,8 +86,24 @@ public class Client extends Ice.Application synchronized(this) { _session = factory.create(name); - _refresh = new SessionRefreshThread(communicator().getLogger(), 5000, _session); - _refresh.start(); + _executor.scheduleAtFixedRate(new Runnable() + { + public void + run() + { + try + { + _session.refresh(); + } + catch(Ice.LocalException ex) + { + communicator().getLogger().warning("SessionRefreshThread: " + ex); + // Exceptions thrown from the executor task supress subsequent execution + // of the task. + throw ex; + } + } + }, 5, 5, java.util.concurrent.TimeUnit.SECONDS); } java.util.ArrayList<HelloPrx> hellos = new java.util.ArrayList<HelloPrx>(); @@ -235,22 +202,10 @@ public class Client extends Ice.Application cleanup(boolean destroy) { // - // The refresher thread must be terminated before destroy is + // The refresher task must be terminated before destroy is // called, otherwise it might get ObjectNotExistException. // - if(_refresh != null) - { - _refresh.terminate(); - try - { - _refresh.join(); - } - catch(InterruptedException e) - { - } - _refresh = null; - } - + _executor.shutdown(); if(destroy && _session != null) { _session.destroy(); @@ -266,6 +221,6 @@ public class Client extends Ice.Application System.exit(status); } - private SessionRefreshThread _refresh = null; + private java.util.concurrent.ScheduledExecutorService _executor = java.util.concurrent.Executors.newScheduledThreadPool(1); private SessionPrx _session = null; } diff --git a/java/demo/Ice/session/ReapTask.java b/java/demo/Ice/session/ReapTask.java new file mode 100644 index 00000000000..39b8bb1fad5 --- /dev/null +++ b/java/demo/Ice/session/ReapTask.java @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +class ReapTask implements Runnable +{ + static class SessionProxyPair + { + SessionProxyPair(Demo.SessionPrx p, SessionI s) + { + proxy = p; + session = s; + } + + Demo.SessionPrx proxy; + SessionI session; + } + + synchronized public void + run() + { + java.util.Iterator<SessionProxyPair> p = _sessions.iterator(); + while(p.hasNext()) + { + SessionProxyPair s = p.next(); + try + { + // + // Session destruction may take time in a + // real-world example. Therefore the current time + // is computed for each iteration. + // + if((System.currentTimeMillis() - s.session.timestamp()) > _timeout) + { + String name = s.proxy.getName(); + s.proxy.destroy(); + System.out.println("The session " + name + " has timed out."); + p.remove(); + } + } + catch(Ice.ObjectNotExistException e) + { + p.remove(); + } + } + } + + synchronized public void + terminate() + { + _sessions.clear(); + } + + synchronized public void + add(SessionPrx proxy, SessionI session) + { + _sessions.add(new SessionProxyPair(proxy, session)); + } + + private final long _timeout = 10 * 1000; // 10 seconds. + private java.util.List<SessionProxyPair> _sessions = new java.util.LinkedList<SessionProxyPair>(); +} diff --git a/java/demo/Ice/session/ReapThread.java b/java/demo/Ice/session/ReapThread.java deleted file mode 100644 index f29e589df70..00000000000 --- a/java/demo/Ice/session/ReapThread.java +++ /dev/null @@ -1,87 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class ReapThread extends Thread -{ - static class SessionProxyPair - { - SessionProxyPair(Demo.SessionPrx p, SessionI s) - { - proxy = p; - session = s; - } - - Demo.SessionPrx proxy; - SessionI session; - } - - synchronized public void - run() - { - while(!_terminated) - { - try - { - wait(1000); - } - catch(InterruptedException e) - { - } - - if(!_terminated) - { - java.util.Iterator<SessionProxyPair> p = _sessions.iterator(); - while(p.hasNext()) - { - SessionProxyPair s = p.next(); - try - { - // - // Session destruction may take time in a - // real-world example. Therefore the current time - // is computed for each iteration. - // - if((System.currentTimeMillis() - s.session.timestamp()) > _timeout) - { - String name = s.proxy.getName(); - s.proxy.destroy(); - System.out.println("The session " + name + " has timed out."); - p.remove(); - } - } - catch(Ice.ObjectNotExistException e) - { - p.remove(); - } - } - } - } - } - - synchronized public void - terminate() - { - _terminated = true; - notify(); - - _sessions.clear(); - } - - synchronized public void - add(SessionPrx proxy, SessionI session) - { - _sessions.add(new SessionProxyPair(proxy, session)); - } - - private final long _timeout = 10 * 1000; // 10 seconds. - private boolean _terminated = false; - private java.util.List<SessionProxyPair> _sessions = new java.util.LinkedList<SessionProxyPair>(); -} diff --git a/java/demo/Ice/session/Server.java b/java/demo/Ice/session/Server.java index 558fc472aef..4f8582a0775 100644 --- a/java/demo/Ice/session/Server.java +++ b/java/demo/Ice/session/Server.java @@ -21,21 +21,17 @@ public class Server extends Ice.Application } Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionFactory"); - ReapThread reaper = new ReapThread(); - reaper.start(); + + java.util.concurrent.ScheduledExecutorService executor = java.util.concurrent.Executors.newScheduledThreadPool(1); + ReapTask reaper = new ReapTask(); + executor.scheduleAtFixedRate(reaper, 1, 1, java.util.concurrent.TimeUnit.SECONDS); adapter.add(new SessionFactoryI(reaper), communicator().stringToIdentity("SessionFactory")); adapter.activate(); communicator().waitForShutdown(); + executor.shutdown(); reaper.terminate(); - try - { - reaper.join(); - } - catch(InterruptedException e) - { - } return 0; } diff --git a/java/demo/Ice/session/SessionFactoryI.java b/java/demo/Ice/session/SessionFactoryI.java index 95e6be954b2..0695713b271 100644 --- a/java/demo/Ice/session/SessionFactoryI.java +++ b/java/demo/Ice/session/SessionFactoryI.java @@ -11,7 +11,7 @@ import Demo.*; class SessionFactoryI extends _SessionFactoryDisp { - SessionFactoryI(ReapThread reaper) + SessionFactoryI(ReapTask reaper) { _reaper = reaper; } @@ -32,5 +32,5 @@ class SessionFactoryI extends _SessionFactoryDisp c.adapter.getCommunicator().shutdown(); } - private ReapThread _reaper; + private ReapTask _reaper; } |