Just to clear the out use case, i have multiple instances of the same code
triggered at same time on same machine for different set of data, the data
apparently is huge and hence, i am trying to use different database itself
for each instance based on some condition. However, since the code contains
the part where H2 server is also started inside the code, hence for all
these instances, the h2 server start up is triggered consecutively. I was
expecting it to fail at startup with exception saying that the port is
already in use or something, however, it didn't and it shows as server
started for every instance.
Now, my question is how is it possible?
And say if it is somehow possible, now once one instance says server.stop()
on the server, will this affect all the other servers running in other java
processes?
On Tuesday, 16 June 2015 17:56:39 UTC+5:30, Vatsal Garg wrote:
>
> 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.