Hi, 

I am trying to start H2 Server from java code. Everything seems to be 
working fine, however, the application module developed has multiple 
instances triggering this part of the code at various time, which may also 
overlap with each other. Hence, i was expecting an error while starting the 
server in these overlapping conditions, but seems that the server does not 
throw any exception. 

Why is there such a behavior? 

I am sharing few snippets as below. 

public class Maintainence {

    private Setting setting;

    private static H2ServerManager serverManager;

    public Maintainence() throws IOException, IllegalPropertyException {
        setting = Setting.getINSTANCE(null);
    }

    public void startH2Server() throws SQLException {
        serverManager = new H2ServerManager("-tcpAllowOthers");
        serverManager.startServer();
    }

    public void stopH2Server() {
        serverManager.stopServer();
    }
}


package com.nsn.mvicm.huawei.mainapp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Properties;

import com.nsn.mvicm.exceptions.IllegalPropertyException;
import com.nsn.mvicm.huawei.common.cleanup.Maintainence;
import com.nsn.mvicm.huawei.common.setting.Setting;

public class Test {

    Maintainence maintainence;
    
    Setting setting;
    
    public static Properties getProperties(String args) {
        Properties properties = null;
        try {
            File file = new File(args);
            FileInputStream fileInput = new FileInputStream(file);
            properties = new Properties();
            properties.load(fileInput);
            fileInput.close();
            Enumeration<Object> enuKeys = properties.keys();
            while (enuKeys.hasMoreElements()) {
                String key = (String) enuKeys.nextElement();
                String value = properties.getProperty(key);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    public static void main(String args[]) throws IOException, 
IllegalPropertyException, SQLException, InterruptedException {
        Test test = new Test();
        test.setting = Setting.getINSTANCE(getProperties(args[0]));
        test.maintainence = new Maintainence();
        test.maintainence.startH2Server();
        
        Thread.sleep(20000);
        
        test.maintainence.stopH2Server();
    }
}

When i run this test class twice in Eclipse, i dont get any Exception, and 
both the instances run fine. 
Why is there such a behavior? 

Br,
Vatsal

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to