Rajdeep Biswas

Ranch Hand
+ Follow
since Mar 26, 2012
Rajdeep likes ...
Eclipse IDE Java Opera
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajdeep Biswas

Alright Dave. Checking and setting retries to 1 for wrong values was in my mind. Just thought if we have a better piece of code in the same manner as do ... (once), and while ...(retries) - try-again. It wont be an issue though, I will go with former only if thats that.
8 months ago
Ok, I am going to put things once again.

1. I am reading number of retries from outside.
2. Now, dont take it literally. If I read a value of 3 in retries, then, sat if we have the known exception in each execution, then total number of times the operation is executed is 3 (including original request, effectively meaning 2 retries instead of 3). Please ignore this thing. I will modify it later.
3. The way catch is defined and handled also is not in the scope of my discussion.

Here I am reiterating my issue:

1. If I do like this:

then I am getting issue that variable "retries" is not read. So to resolve this, I tried below:
this now removes above problem but introduces another problem - redundant initialization of "retries", i.e. without being used, retries is being reassigned another value.
So I am looking for a clean approach to write it in a better way.
Here are my considerations:
  • The first call should be independent of whatever value we read for 'retries'
  • Duplicate code should be avoided, and avoiding recursion will be nice too.
  • 8 months ago
    That is not my problem at all. Please read the last statements in original post.
    8 months ago
  • The first call should be independent of whatever value we read for 'retries'
  • Duplicate code should be avoided, and avoiding recursion will be nice too.

  • May be a simple thing, but I am not catching it probably. Please suggest.
    8 months ago
    As I said, it calls a boolean returning method passing on the exception object, and in the method we check for exception message contents and other things. But I wonder why should it matter because the assumption is that if the condition is met, i.e. if the method returns true, then we think of retry, anything else we throw the exception. My concerns I have put.

    8 months ago
    The instanceof is not there, just I added to make others understand. There is a method call that checks the contents of the exception.
    8 months ago
    Here's the logic I used:

    Number of retries is considering original operation as well. But the problem is that

    if I return from try block directly without assigning anything, then SCA (Fortify for me) reports that the variable retries is not read (in success flow), and
    if I assign and do as above, then SCA shouts about the immediate reassignment of value to the retries variable without even reading it.
    How do I write it nicely?

    8 months ago
    Welcome Mala. I hope readers and you both have great success with this book.

    Stephan van Hulst wrote:Understanding recursion lies in believing that the recursive step "just works".

    When I tried to solve it, thinking about individual movements confused me. Then I trusted recursion, thought about a single disk case calling that in recursion, and wrote the base condition, again just a print. It worked. When I go into it, it still utterly confuses me. So I am half in half out!   
    1 year ago
    For definition of exception, head to google.
    In regex, you simply match input for a given pattern without worrying for exceptions. Using parseInt or parseLong, you actually try to parse given string input to number (needed when you need given string input as a number in your application, since external inputs are always as String) and in case of error, gives exception that you should handle.
    In regex, you just match the input against a pattern without the worry of exceptions, since you are not actually parsing it to number.
    For example, head to http://regexr.com/3dmdj and mouseover the pattern.
    1 year ago
    Regex is also a way, but thing the OP mentioned, I think the simplest way will be to do Integer.parseInt(). If exception is thrown, its not a number. If not, its cool! Thinking this functionality will go in some utility method, just handle the NumberFormatException and return boolean appropriately.
    1 year ago
    Yup, please explain more. From the little understanding that I got, I think both threads are not doing inter-thread communication properly, or probably you needed to implement some polling mechanism against some state of your services. If you are knowing what you are trying to accomplish, BlockingQueue might be a good option too.
    1 year ago
    For anyone stumbling across this, here is the raw code; https://github.com/xploreraj/ytools/
    1 year ago
    Its pertinent that in case of threads working on some instance methods, it acquires the monitor or lock of that object and then goes in to operate.
    I am thinking that there might be some kind of registry with this instance information and some flag in there that says whether its acquired or not.
    I was just wandering where this information is stored and how is it shared between threads. It'll be great to know in case someone sheds some light on this.
    1 year ago