Revision 47348 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialUtils.java

View differences:

H2SpatialUtils.java
21 21
    private static boolean startServer = true;
22 22
    private static boolean lastAllowOthers = true;
23 23
    private static String lastPort = "9123";
24
    
24

  
25
    private static Thread shutdownHook = new Thread("H2_shutdown_hook") {
26
        @Override
27
        public void run() {
28
            server_stop();
29
        }
30
    };
31

  
25 32
    public static File[] getH2Files(File f) {
26 33
        if( f==null ) {
27 34
            return null;
......
168 175
        return connectionURL;
169 176
    }
170 177
    
171
    public static void server_stop() {
178
    public static synchronized void server_stop() {
172 179
            if (h2server == null) {
173 180
                LOGGER.info("The H2 server is already stopped.");
174 181
            } else {
......
198 205
        server_start(lastPort, lastAllowOthers);
199 206
    }
200 207
    
201
    public static void server_start(String port, Boolean allowOthers) {
208
    public static synchronized void server_start(String port, Boolean allowOthers) {
202 209
            if( !enable_server ) {
203 210
                return;
204 211
            }
......
222 229
                    LOGGER.info("  Engine version : h2 "+ org.h2.engine.Constants.getFullVersion()+", h2gis "+H2GISversion.geth2gisVersion());
223 230
                    LOGGER.info("  Connection url : jdbc:h2:"+h2server.getURL()+"/ABSOLUTE_DATABASE_PATH;MODE=PostgreSQL;SCHEMA=PUBLIC;ALLOW_LITERALS=ALL");
224 231
                    LOGGER.info("  status:"+ h2server.getStatus());
225
                    Runtime.getRuntime().addShutdownHook(new Thread() {
226
                        @Override
227
                        public void run() {
228
                            server_stop();
229
                        }
230
                    });
232
                    Runtime.getRuntime().removeShutdownHook(shutdownHook);
233
                    Runtime.getRuntime().addShutdownHook(shutdownHook);
231 234
                    lastPort = port;
232 235
                    lastAllowOthers = allowOthers;
233 236
                } catch (SQLException ex) {
......
250 253
        return enable_server;
251 254
    }
252 255
    
253
    public static boolean is_server_started() {
256
    public static synchronized boolean is_server_started() {
254 257
        return h2server!=null;
255 258
    }
256 259
}

Also available in: Unified diff