Category: Java


Coldfusion has a great function called “gettickcount()” which basically gives you the current time in milliseconds. This is a great function to time code. Look at the example below:

<cfset stime = getTickCount()>
<!— All my code to time here —>
<cfloop from=“1″ to=“100″ index=“i”>
<cfoutput>testing #i#</cfoutput>
<!— Make a call here —>
</cfloop>
<cfset totalTime = getTickCount() – stime>
<cfoutput>The total time of execution for the code was: #totalTime#</cfoutput>

This utility is great. The question is, how do I do this in Java?? Well very simple, we use the System class. The following is a simple snippet of how to time in java.

double stime = System.currentTimeMillis();
//My Code Here


for(int i=0;i< 1000; i++){
System.out.println(i);
}
double TotalTime = System.currentTimeMillis() – stime;
//Display Total Time

System.out.println(“Total Time of Execution: “ + TotalTime + “ms.”);

There you go!! Now you can time your java code.

Every wonder a nice, quick and easy way of getting your Operating System’s file separator character??

Well, I have several times. Thanks to our collaborator Ariel Gonzalez, and his java expertise. We take a look at the java.lang.System class and its getProperty() Method.

There are several useful properties that you can get from this class, some of them are listed below:

This snippet utilizes the power of java to create an execution sleep timer. There are various applications for this snippet, but the purpose of the snippet is to provide you with a mechanism of making the coldfusion thread sleep for a period of time. Please be careful when setting the timer variable since it might just lock the execution thread.

I have also included a copy-paste snippet of my actual CFC function.

The snippet is actually very simple:

<cfset thread = CreateObject(“java”, "java.lang.Thread”)>
<cfset thread.sleep(arguments.milliseconds)>

I have been recently introduced to this great database utility tool, Aqua Data Studio

It is an incredible database tool, you can connecto to Oracle, MySQL, MS Sql, DB2, or an JDBC complaint database. It has an incredible Procedure Editor, Query Analyzer, Schema Browser, and best of all, written in JAVA.

The GUI is great and provides great graphical browsing of any database. I truly love this utility.

You can download it from here. Please check it out.

Coldfusion introduced the use of web services in coldfusion MX and what a great feature. However, there are some intricacies on this feature. Web Service stubs, stubs are created by Java in order to define the signature of a web service. This holds the request and response headers, the arguments and their data types. So if a change in signature occurs, the stubs need to be refreshed or recreated. You can either do this programmatically or manually.

Most of the time the programatic approach will work, but sometimes these little bastards persist. So you have to follow a procedure and clean them out. Below you will find the programmatic way first:

<cfobject type=“JAVA”
action=“Create”
name=“factory”
class=“coldfusion.server.ServiceFactory”>

<cfset RpcService = factory.XmlRpcService>

<cfset RpcService.refreshWebService(http://testwebsite/webservice/myservice.cfc?wsdl)>

This is a pretty useful snippet for a clustered environment. It is a simple java snippet to get your local server host name. Please remember that if your servers are Unix based, this values are retrieved from the /etc/hosts file.

<cfset inet = CreateObject(“java”, “java.net.InetAddress”)>
<cfset inet = inet.getLocalHost()>
<cfoutput>#inet.getHostName()#</cfoutput>
Powered by WordPress. Theme: Motion by 85ideas.