0

I'm new to Java, so this may be obvious, but consider the following two blocks of code. Version A leaves the server spinning forever, but Version B spins up then terminates the server. What is the function of the try block here?

Version A:

import org.apache.ignite.Ignition;
import org.apache.ignite.Ignite;
public class Test {
    public static void main(String[] args)
    {
        Ignite ignite = Ignition.start();
        return;
    }
}

Version B:

import org.apache.ignite.Ignition;
import org.apache.ignite.Ignite;
public class Test {
    public static void main(String[] args)
    {
        try(Ignite ignite = Ignition.start())
        {
            return;
        }
    }
}
Carbon
  • 3,828
  • 3
  • 24
  • 51

1 Answers1

1

Ignite instance is declared in a try-with-resource statement, it will be closed regardless of whether the try statement completes normally. For more details about this you can visit https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

thebishal
  • 71
  • 6