Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 53
Like Tree5Likes

Thread: Why does Java process things very long?

  1. #21
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    Quote Originally Posted by gimbal2 View Post
    Using a profiler is still less effort. But I'll meet you halfway, because it is also an approach that requires a more experienced mind, your suggestion of adding timing code is more fitting for people who are still in the code hacking phase of their upbringing.
    Well, what should I do? What is the problem?

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Why does Java process things very long?

    Does the program's execution end? How long does it run for? Can you use the java command's -Xprof option to get a profile of the program's execution?
    If you don't understand my response, don't ignore it, ask a question.

  3. #23
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Tawi View Post
    Well, what should I do? What is the problem?
    You need to narrow your problem down. What part of your program is taking a long time? You mentioned that your program is doing some calculations. Which *part* of those calculations is taking a long time?

    One of the simplest ways to figure this out is to add print statements that time the different parts of your program. Something like this:

    Java Code:
    long start = System.currentTimeMillis();
    //do part one
    long elapsed = System.currentTimeMillis() - start;
    System.out.println("Part one took: " + elapsed);
    
    start = System.currentTimeMillis();
    //do part two
    elapsed = System.currentTimeMillis() - start;
    System.out.println("Part twotook: " + elapsed);
    
    start = System.currentTimeMillis();
    //do part three
    elapsed = System.currentTimeMillis() - start;
    System.out.println("Part threetook: " + elapsed);
    Using this approach you can figure out which part of the program is taking a long time. For example, maybe my above code tells me that part one takes 1 second, part two takes 45 seconds, and part three takes 2 seconds. That tells me that my problem is in part two, and I can ignore parts one and three for now. Then you can repeat that process inside part two: which part of it is taking a long time?

    This is what we mean when we say you need to isolate the problem. There really isn't much else we can do until you narrow your problem down further.
    Last edited by KevinWorkman; 02-19-2014 at 03:24 PM.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #24
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    Quote Originally Posted by KevinWorkman View Post
    You need to narrow your problem down. What part of your program is taking a long time? You mentioned that your program is doing some calculations. Which *part* of those calculations is taking a long time?

    One of the simplest ways to figure this out is to add print statements that time the different parts of your program. Something like this:

    [highlight=java]
    long start = System.currentTimeMillis();
    //do part one
    long elapsed = System.currentTimeMillis() - start;
    System.out.println("Part one took: " + elapsed);

    start = System.currentTimeMillis();
    //do part two
    elapsed = System.currentTimeMillis() - start;
    System.out.println("Part twotook: " + elapsed);

    start = System.currentTimeMillis();
    //do part three
    elapsed = System.currentTimeMillis() - start;
    System.out.println("Part threetook: " + elapsed);
    [/highlight]

    Using this approach you can figure out which part of the program is taking a long time. For example, maybe my above code tells me that part one takes 1 second, part two takes 45 seconds, and part three takes 2 seconds. That tells me that my problem is in part two, and I can ignore parts one and three for now. Then you can repeat that process inside part two: which part of it is taking a long time?

    This is what we mean when we say you need to isolate the problem. There really isn't much else we can do until you narrow your problem down further.
    I want to do that but every part in my program is related one another so how can I break it? I was trying to break it and can only make it 10 lines shorter so?

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Why does Java process things very long?

    There must be loops or calls to methods the you can use the end time minus start time computations that Kevin suggested to isolate where time is being spent. Its an iterative process. Try here, try there. As you find areas that take time, go into them and add more end-start time measures.
    If you don't understand my response, don't ignore it, ask a question.

  6. #26
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Norm View Post
    There must be loops or calls to methods the you can use the end time minus start time computations that Kevin suggested to isolate where time is being spent. Its an iterative process. Try here, try there. As you find areas that take time, go into them and add more end-start time measures.

    It takes a long time after I give a "proses" name to a button and press it. So? Why? Please enable the button and download the file. Analyzed the files please and after that please tell me the problem that I am having. Please do this because I do not know how to do it although you give me a link to make it shorter.

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Why does Java process things very long?

    Have you tried what Kevin and I suggested to find where the program is spending time executing?
    You need to do some work to solve your problem.
    If you don't want to do anything with the code, then hire a java programmer to do it.
    If you don't understand my response, don't ignore it, ask a question.

  8. #28
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Tawi View Post
    Please enable the button and download the file.
    Nope! But if this keeps up this thread will be longer than your process.

    Regards,
    Jim
    KevinWorkman likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #29
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Tawi View Post
    It takes a long time after I give a "proses" name to a button and press it. So? Why?
    What exactly does the button do? Split that up into two halves, timing each half like I showed you. Does one half take significantly longer? If so, split that half into to halves again, and repeat the process until you have your problem narrowed down to just a few lines. If you're still not sure why those few lines take so long, post them here in the form of an SSCCE and we'll be glad to help.

    Quote Originally Posted by Tawi View Post
    Please enable the button and download the file. Analyzed the files please and after that please tell me the problem that I am having. Please do this because I do not know how to do it although you give me a link to make it shorter.
    Please follow the advice you've already been given. If you're just going to ignore the advice we've given you, why should we continue giving you advice?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #30
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    Quote Originally Posted by KevinWorkman View Post
    What exactly does the button do? Split that up into two halves, timing each half like I showed you. Does one half take significantly longer? If so, split that half into to halves again, and repeat the process until you have your problem narrowed down to just a few lines. If you're still not sure why those few lines take so long, post them here in the form of an SSCCE and we'll be glad to help.



    Please follow the advice you've already been given. If you're just going to ignore the advice we've given you, why should we continue giving you advice?
    The button will process every calculation that is needed by the program. So? Can you help?

    Well, I have several methods but if I post them seperately, will they work? Please just download the files and tell me the problem of my program. My deadline is approaching. I must finish the program before April or they will kick me out. Please help.

  11. #31
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Tawi View Post
    The button will process every calculation that is needed by the program. So? Can you help?
    I've already told you exactly what to do. Why are you ignoring the advice you're receiving?

    Quote Originally Posted by Tawi View Post
    Well, I have several methods but if I post them seperately, will they work? Please just download the files and tell me the problem of my program. My deadline is approaching. I must finish the program before April or they will kick me out. Please help.
    Don't post your methods separately. Boil you problem down to an SSCCE using the advice you're received. You're wasting time constantly asking people to look at your full code, and honestly, if you don't know how to isolate a problem and debug it, you probably should be kicked out.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #32
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    I tried to break it up. I omit the login part because I have a little problem with that. Breaking them that way only make them ten lines shorter, so? Every forum suggest me to do that but you know, it is an integrated program. Breaking it can make the program fail.

  13. #33
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Tawi View Post
    I tried to break it up. I omit the login part because I have a little problem with that. Breaking them that way only make them ten lines shorter, so?
    You have to learn how to isolate your code. This is programming 101. If the login has nothing to do with the problem, then for your test purposes, hardcode the login information that's required by the next piece. Have you tried timing different parts of your program yet? Which part takes the longest? Have you tried timing the different parts of that part?

    Quote Originally Posted by Tawi View Post
    Every forum suggest me to do that but you know, it is an integrated program. Breaking it can make the program fail.
    What other forums have you posted this question on? It's considered pretty rude to crosspost without providing links between the discussions.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #34
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    Well, I am sorry. I am not trying to be rude but they are not answering me well. Well, the process after I click the button that I put "Proses" name take almost a day. After a day, it doesn't finish the whole jobs, so? Different problems but the same program.

  15. #35
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Why does Java process things very long?

    Quote Originally Posted by Tawi View Post
    Well, I am sorry. I am not trying to be rude but they are not answering me well. Well, the process after I click the button that I put "Proses" name take almost a day. After a day, it doesn't finish the whole jobs, so? Different problems but the same program.
    What other forums have you posted this in?

    Which *part* of the process takes that long? I've explained how to figure it out. I'm not sure what else you want. If you want somebody to figure it out for you, you're going to have to hire a programmer.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #36
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: Why does Java process things very long?

    Look, please just activate the link and download the files because it is not doing anythings after I put your advise to my program. What shall I do?

  17. #37
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: Why does Java process things very long?

    Now I know what an infinite loop feels like.

    Or perhaps we are all participating in a Turing test.

    Regards,
    Jim
    Last edited by jim829; 02-20-2014 at 05:29 PM.
    KevinWorkman likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  18. #38
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: Why does Java process things very long?

    One word: profiler. (Shameless plug) I spent 400 euros on JProfiler and never looked back at petty performance problems. The information you get is priceless. Or find a free one. I don't care.

    The sentence "I have performance issues" should be followed by the sentence "I will start my profiler now". If that shows some code that you don't know how to get faster, then by all means, show it to us in the dreaded SSCCE, and we can help.
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  19. #39
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Why does Java process things very long?

    Quote Originally Posted by SurfMan View Post
    One word: profiler.
    I'm glad we agree, we Dutch people need to stick together still being a minority in this forum ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  20. #40
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: Why does Java process things very long?

    Quote Originally Posted by gimbal2 View Post
    I'm glad we agree, we Dutch people need to stick together still being a minority in this forum ;)
    Tru dat :)

    OT: Interpreting the output of a profiler takes some time to learn. Start with profiling some "easy" code to make sure you know what you see, and you can interpret the results correctly.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 06-02-2013, 12:43 PM
  2. What are some cool begginer things to do with Java?
    By CiniCraft in forum New To Java
    Replies: 2
    Last Post: 09-11-2011, 11:13 PM
  3. Replies: 6
    Last Post: 03-23-2011, 07:53 PM
  4. A good Java installation package can make things much easier
    By freezea in forum Reviews / Advertising
    Replies: 2
    Last Post: 02-01-2009, 01:03 PM
  5. May someone explain what these things means in Java
    By quickfingers in forum New To Java
    Replies: 2
    Last Post: 01-26-2008, 06:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •