5 Replies Latest reply on Nov 5, 2006 1:38 PM by shloime11

    Java HELP!

    Level 7
      I found this code to pause the execution of a page by a set amount of
      seconds

      I need to figure out how to use this in CF so I can pause the execution of a
      loop.

      Can anyone help?

      public class Wait {
      public static void oneSec() {
      try {
      Thread.currentThread().sleep(1000);
      }
      catch (InterruptedException e) {
      e.printStackTrace();
      }
      }
      }

      Can I put it into a <cfscript> tag? Then how can I call it inside a loop?


        • 1. Re: Java HELP!
          Level 7
          Nevermind, I did it a different way


          • 2. Re: Java HELP!
            ksmith Level 1
            Here is a call to the Thread.sleep method:
            • 3. Re: Java HELP!
              shloime11
              Hi,

              I'm trying to use the sleep script you provided and when I try to variblize the time using some calculations (see the example below) it throws the following error:

              The selected method sleep was not found.
              Either there are no methods with the specified method name and argument types, or the method sleep is overloaded with arguments types that ColdFusion can't decipher reliably. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.

              Example:

              <cfset SleepSeconds = 1000 * 2>
              <cfscript>
              thrObj = CreateObject("java", "java.lang.Thread");
              thrObj.sleep(#SleepSeconds#);
              </cfscript>

              Any Ideas would be greatly appreciated.
              • 4. Re: Java HELP!
                Level 7
                shloime11 wrote:
                > <cfset SleepSeconds = 1000 * 2>


                > <cfscript>
                > thrObj = CreateObject("java", "java.lang.Thread");
                > thrObj.sleep(#SleepSeconds#);
                > </cfscript>

                sleep method is looking for a java "long". since you did some calculations on
                SleepSeconds cf converts into a float (i think). use javacast

                thrObj.sleep(javaCast("long",SleepSeconds));
                • 5. Re: Java HELP!
                  shloime11 Level 1
                  Thanks! This did the trick