PDA

View Full Version : Flow of the program


Lavanya9
Dec 22, 2015, 05:47 AM
could you please explain the flow of program, is resource leak is happening in this code

package nttdata;


import javax.naming.InitialContext;
import javax.naming.NamingException;


public class Sample{


public void test000(){
try {
InitialContext ctx = new InitialContext();
} catch (NamingException e) {
e.printStackTrace();
}
}


public void test001(){
try {
InitialContext ctx = new InitialContext();
call001(ctx);
} catch (NamingException e) {
e.printStackTrace();
}
}

public void call001(InitialContext ctx){
// do nothing.
}



public void test002(){
try{
InitialContext ctx = new InitialContext();
call002(ctx);
}catch(NamingException e){
e.printStackTrace();
}
}

private boolean isTrue = false;

public void call002(InitialContext ctx){
if(this.isTrue){
try{
ctx.close();
}catch(NamingException e){
e.printStackTrace();
}
}
}


}

CravenMorhead
Dec 22, 2015, 08:58 AM
Where is the main function that calls this class? Do you think there are resource leaks?

Lavanya9
Dec 22, 2015, 08:34 PM
Hai,
Good Morning :)
Yes, I have this code myself, I want to know how the flow is in this code
I want to know main difference between the flow of two methods (test001 and test002)

is test001 and test002 functionality same?

public void test001(){
try {
InitialContext ctx = new InitialContext();
call001(ctx);
} catch (NamingException e) {
e.printStackTrace();
}
}

public void call001(InitialContext ctx){
// do nothing.
}


public void test002(){
try{
InitialContext ctx = new InitialContext();
call002(ctx);
}catch(NamingException e){
e.printStackTrace();
}
}

private boolean isTrue = false;

public void call002(InitialContext ctx){
if(this.isTrue){
try{
ctx.close();
}catch(NamingException e){
e.printStackTrace();
}
}
}


}

Hai,
Good Morning :)


Yes, I have this code myself, I want to know how the flow is in this code
I want to know main difference between the flow of two methods (test001 and test002)


is test001 and test002 functionality same??


public void test001(){
try {
InitialContext ctx = new InitialContext();
call001(ctx);
} catch (NamingException e) {
e.printStackTrace();
}
}


public void call001(InitialContext ctx){
// do nothing.
}




public void test002(){
try{
InitialContext ctx = new InitialContext();
call002(ctx);
}catch(NamingException e){
e.printStackTrace();
}
}


private boolean isTrue = false;


public void call002(InitialContext ctx){
if(this.isTrue){
try{
ctx.close();
}catch(NamingException e){
e.printStackTrace();
}
}
}




}