Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Flow of the program (https://www.askmehelpdesk.com/showthread.php?t=819681)

  • Dec 22, 2015, 05:47 AM
    Lavanya9
    Flow of the program
    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();
    }
    }
    }


    }
  • Dec 22, 2015, 08:58 AM
    CravenMorhead
    Where is the main function that calls this class? Do you think there are resource leaks?
  • Dec 22, 2015, 08:34 PM
    Lavanya9
    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();
    }
    }
    }




    }

  • All times are GMT -7. The time now is 05:14 PM.