Recursive code runs slowly in a UNIX window, but runs fast in windows

I have Java code that is a combination of a while loop and recursion. The problem that we are facing is that calling the method below takes almost 8 times longer in the unix window [HP ProLiant BL460c G7] than the window [Intel Xeon CPU E5-1650, 64 bit Windows 7]. Any ideas on how to improve runtime in a Unix block. We are using JDK 1.6_43 [64 bit]

protected Date abc(int n, Date date) 
{
    long tStart = System.currentTimeMillis();

    if (n > 0) 
    {
          while (n > 0)
          {
                --n;
                date = getNextExchangeDateUnadjusted(date);
          }

          return date;
    }
    else 
    {

          Date nextExchangeDate = getNextExchangeDateUnadjusted(date);

          Date previousExchangeDate = getNextExchangeDateUnadjusted(date);

          while (!abc( -n + 1, previousExchangeDate).equals(nextExchangeDate)) 
          {

                date = date.addDays( -14);

                previousExchangeDate = getNextExchangeDateUnadjusted(date);

          }

          return previousExchangeDate;
    }
}

EDIT:

Below is the code for the method getNextExchangeDateUnadjustedthat is called above

public Date getNextExchangeDateUnadjusted(Date date) {
    // Third Wednesday of each month
    Date thirdWednesdayInMonth = date.getThirdWednesdayInMonth();
    if (thirdWednesdayInMonth.after(date)) {     
      return thirdWednesdayInMonth;
    }
    return date.addMonths(1).getThirdWednesdayInMonth();
  }
}

I also want to add that this code spends the maximum time in this part:

      while (!abc( -n + 1, previousExchangeDate).equals(nextExchangeDate)) 
      {

            date = date.addDays( -14);

            previousExchangeDate = getNextExchangeDateUnadjusted(date);

      }

EDIT2:

Unix, , , "Retained Heap" 1 4,5 , . , . Windows, XSS.

+4
2

:

  • IO , .
  • Visual VM, - , Unix windows. , , , 4,5 , Unix, .
  • , , JVM unix windows, - .

3 , , java -version

  • Windows

    java version "1.6.0_43"

    Java (TM) SE Runtime Environment ( 1.6.0_43-b01)

    Java HotSpot (TM) 64- VM ( 20.14-b01, )

  • Unix

    java version "1.6.0_43"

    Java (TM) SE Runtime Environment ( 1.6.0_43-b01)

    64- Java HotSpot TM ( 20.14-b01, )

JVM hotspot unix windows. , JVM, Interpreted, [ : https://blog.codecentric.de/en/2012/07/useful-jvm-flags-part-1-jvm-types-and-compiler-modes/]. , Unix -Xmixed, JVM . , Unix Windows .

EDIT:

JVM - unix box: -Djava.compiler=NONE

+1

, .

assume abc is initially called as abc(1, "date < 3th Wednesday")
it will return "3th Wednesday in the same month"

assume abc is initially called as abc(0, "date < 3th Wednesday")
1. while loop iteration
abc(1, 3th Wednesday in the same month)
  - return 3th Wednesday of month+1
- as this is not equal with the "3th Wednesday in the same month"
   (nextExchangeDate) you compute "date - 14 day"
2. while loop iteration abc will be called as abc(1, "date - 14 day")
which return "3th Wednesday of month-1"
3. while loop iteration abc will be called as abc(1, "3th Wednesday of month-1")
...

. , . , .

,

"16.11.2015" n = 1

abc(1, 16.11.2015)
16.11.2015 get 3th Wed ==> 18.11.2015
abc date: 18.11.2015

"16.11.2015" n = 0

abc(0, 16.11.2015)
16.11.2015 get 3th Wed ==> 18.11.2015
16.11.2015 get 3th Wed ==> 18.11.2015
abc(1, 18.11.2015)
18.11.2015 get 3th Wed ==> 18.11.2015
18.11.2015 + (1) month
18.12.2015 get 3th Wed ==> 16.12.2015
16.11.2015 + (-14) days
02.11.2015 get 3th Wed ==> 18.11.2015
abc(1, 18.11.2015)
18.11.2015 get 3th Wed ==> 18.11.2015
18.11.2015 + (1) month
18.12.2015 get 3th Wed ==> 16.12.2015
02.11.2015 + (-14) days
19.10.2015 get 3th Wed ==> 21.10.2015
abc(1, 21.10.2015)
21.10.2015 get 3th Wed ==> 21.10.2015
21.10.2015 + (1) month
21.11.2015 get 3th Wed ==> 18.11.2015
abc date: 21.10.2015 (the 3th Wed of previous month)

, .

-1

Source: https://habr.com/ru/post/1617710/


All Articles