set ANT_OPTS=-Xms512m -Xmx512m (Windows)
export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
now run your build
set ANT_OPTS=-Xms512m -Xmx512m (Windows)
export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
now run your build
mysql> alter tableUPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]
-> changevarchar(100); <-- new data type to be changed to
Update Table
Change value of a Column based on a condition
1. without username / password
shell>mysql
mysql -u username -p database_name < sqlfile.sqldb_name
< sqlfile.sql
>output.txt
2. with username / password
In 5.0, the Java™ programming language gets linguistic support for enumerated types. In their simplest form, these enums look just like their C, C++, and C# counterparts:
enum Season { WINTER, SPRING, SUMMER, FALL }
But appearances can be deceiving. Java programming language enums are far more powerful than their counterparts in other languages, which are little more than glorified integers. The new enum declaration defines a full-fledged class (dubbed an enum type). In addition to solving all the problems mentioned above, it allows you to add arbitrary methods and fields to an enum type, to implement arbitrary interfaces, and more. Enum types provide high-quality implementations of all the Object methods. They are Comparable and Serializable, and the serial form is designed to withstand arbitrary changes in the enum type.
The static import construct allows unqualified access to static members without inheriting from the type containing the static members. Instead, the program imports the members, either individually:
import static java.lang.Math.PI;
or en masse:
import static java.lang.Math.*;
Once the static members have been imported, they may be used without qualification:
double r = cos(PI * theta)
- Short answer –
Yes
- for the impatient but wana know more kind –
only Nested-Top level class can be declared static.
There are 2 types of class Top-level (Opter) and Inner (Anonymous, Local,Member,Nested top-level)
Local – Class declared in a code block or method and is visible inside tha block only like a local variable
Member – is visible for the entire class, you can instantiate this class only with in the context of the object, and hence cannot have its own indivudial existance, and cannot be instantited without an object of the outer class
Nested top level class – is like a member class with static modifier. It is just like anyother top-level class but declaed inside another class,
Soln1: http://sourceforge.net/projects/junit-addons
Look at that. It has a PrivateAccessor class to call private methods and fields. It also has utility classes for array comparision and the likes. I really like it.
Soln2: Make it non-private. Or for every private foo(), add another method foo_FOR_TESTING_ONLY() that calls foo(). Or zap the class with reflection to make the method non-private temporarily.
JCaptcha is one such tool, which will help you do get it into your web App – details in the link
Its very convinent to create a Web Service Client using the tool WSDL2JAVA. Below are the steps to create one in Eclipse.
Step-1. Create a project in Eclipse ( we will call it testWSClient )
Step-2. Create a new run time configuration in Eclipse by clicking on “Run” and the new run time configuration Icon on the pop-up dialog box.
Step-3 - Now Run the runwsdl2java by selecting it from the Run dropdown, you should see the following
Note : It should be noted that all these classes are generated automatically by the wsdl2java tool.
Step-4 - Now Write your Client to invoke and access the methods in the WSDL, and interact with the web services.
NOte : Before we start make sure that the “ServiceHttpPort_address” variable in ServiceLocator class is pointing to the correct WSDL URL, which you provided when you were running the wsdl2java, it normally will be, but this is just a check, might not be required.
Now you can write a client, example below
public static void main(String[] args) throws MalformedURLException
{
Service service = new ServiceLocator();
try {
System.out.println(service.getServiceHttpPort().xyzMethod(getMyObject()));
}
catch (Exception e) {
System.out.println(e.toString());
}
}
private MyObject getMyObject() {
// Note this MyObject will be a complexType in the WSDL and generated by the wsdl2java tool, we are creating it to pass it to the method xyzMethod ( also in WDL as a Port Type and acccessible thru ServiceLocater) which takes MyObject as a parameter
MyObject obj = new MyObject( someparameter);
}
Stop cribbing and fighting and GROW UP!!. Java or PhP it does not matter, what matters is it Works!!!.
So do what it takes to get it done, so if Java or PhP or Even Java and Php together. Still can’t believe. http://www.caucho.com/ have already done it. check it out in their website, they have Resin which is a Open Source application Server and Quercus a Java-Php Bridge.
There is also a Open-Source Php-Java Bridge at Source forge – http://php-java-bridge.sourceforge.net/pjb/
1. Configuring MySql in JBoss
MySQL is an open source database used by many open source projects and small organizations. To use JBoss 4.0 with MySQL, we first need to put the MySQL driver classes into the CLASSPATH
. Copy the .jar file mysql-connector-java-3.0.9-stable-bin.jar to the /server/default/lib directory.
To use the MySQL data source, copy /docs/examples/jca/mysql-ds.xml to the /server/default/deploy directory. Modify the mysql-ds.xml configuration file by setting
to com.mysql.jdbc.Driver
and
to jdbc:mysql://
, where
is the MySQL host server and
is the MySQL database.
After the file is copied to the Deploy folder, this can be monitored from MBean in JMX Console
Next, we need to set the
and
elements in the standardjaws.xml or jaws.xml file:
java:/MySqlDS mySQL
We also need to set the
and
elements in the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml file:
java:/MySqlDS mySQL
Finally, we modify login-config.xml with MySQL database settings. Add the following
element to login-config.xml:
sa sa jboss.jca:service=LocalTxCM,name=MySqlDS
By modifying the mysql-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml, and login-config.xml files, the JBoss 4.0 server is configured to be used with a MySQL database.
Files Attached for reference
2. Programming to talk to MySql in JBoss
“One Cannot refer to a non-final variable form inside an inner class defined in a different method”
public void onModuleLoad() {
// TODO Auto-generated method stub
final FormPanel form = new FormPanel(); –> Has to be final in order to be accessed from an inner class method.
VerticalPanel vpanel = new VerticalPanel();
vpanel.add(form);
vpanel.add(new Button(“Submit”, new ClickListener() {
public void onClick(Widget sender) {
form.submit(); –> Here the final form object is being accessed
}
}));
}
If you are like me, you might be a Developer with moderate knowledge in database. one of the frustrations we face as developers is when we are forced to work with non-indexed tables, which kill application performance.
Well there is a way to get around this in Oracle by using “partitions” , if your DBA has configured one.
partitions are created based on time interval that is set by the DBA’s , usually its 5 0r 10 min window if its a busy table.
when we query this table we would use partition keyword in Oracle to provide partition id to narrow down to the partition. This might need you to be aware of the time stamp when your data was created or updated, as the partition id’s are normally based out of “time stamp”
an example query would look like this – select * from TABLE partition(P200807022035) where field_name=’value’
“P200807022035″ is the partition id which is based on time stamp at 5 min interval ,
P200807022035 – year = 2008, month = 07, day = 02, time = 20:35
Most of us ( Java Developers ) have heard or used tools/apis and frameworks which heavily use Reflection, we might also have used it or at least considered using it at one time or other.
here is a nice article about reflection with great tips on using it and also when to use it. i guess a good opportunity to reflect on your coding history
http://today.java.net/pub/a/today/2008/02/12/reflection-in-action.html
Great Article about GC. click here
List of JVM Options byJoseph D. Mocker (Sun Microsystems, Inc.) – click here
Some Java cmd line options for tuning GC
-Xms initial java heap size
-Xmx maximum java heap size
-Xmn the size of the heap for the young generation
-Xss the stack size for each thread
This is an Interesting Conversation in DevX Form – click here for details.
Question :I have a doubt regarding the working of Class.forName() method.
How exactly it works in jvm? What is the difference between
Class.forName(“oracle.jdbc.driver.OracleDriver”) & DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver())?
If my JDBC code is something like this:
Class.forName(“oracle.jdbc.driver.OracleDriver”);
Class.forName(“Some other driver class”);
Connection conn = DriverManager.getConnection(“jdbcracle:thin:@hostname:1521:SID”,”user”, “pwd”);
Which class will be loaded and how will DriverManager class will know which driver to communicate?
Answer : Short Answer (Summary)
(2)create an instance of that class and store the reference to the variable.
Indexes - Faster Reads / Slower Inserts,Updates,Deletes -
Views – Simpler Query / Slower Reads and more work for DB
De normalization - More Space Req and cost of write operations / Faster Reads with fewer join’s required
Normalization - Lesser Space Req, low cost of write operations / Slower Reads with more join’s required.
Hudson is gaining popularity from startups to Big Blue, ( i wonder how IBM has tutorial on all topics current, and usually they are pretty good ). I have been working on streamling build process and working with Hudson and getting to know it better. some random ramblings and notes with reference below, hope it will be helpful.
Ok not so fast – a brief background first. Have you ever used hudson, is it cool to just run it by typing java -jar hudson.war, well you can do it too, but need to take care of some steps before that, here you go!
1. Cerate your application with all the classes and libraries included, and most importantly ONE MAIN class ( which has a MAIN method ) , lets call it MyDriver.java
2. Now create a test file, input.txt with the following info in it (only one line ), Main-Class: classname In this case it will be Main-Class: MyDriver.java (don’t forget the space after Collen “:” – it wont work otherwise ) - click here for more info and search for “jar”
3. now run this command – jar cfm jar-file manifest-addition input-file(s). In this case it will be jar cfm my.jar input.txt *.* (or *.class what every you want to add ) – click here for details on this command
Finally you have your jar ready to run or rather FLY. you can use this command to do exactly that!
java -jar my.jar ( this should run what ever you have in your main method in your main class ) - clieck here for details
Well they (Apps or users) can’t hide any longer … The Oracle’s best Spy is on your side – here is the SQL which can bring them to the open. ( you need to be the SysDBA to do this though )
1. set linesize 30000 – to make sure everything appears in a single line
2. SQL> select username, sid, serial#, status, osuser, process, machine, terminal, program, logon_time from v$session where username is not null and username not in (‘SYSTEM’,'SYS’,'DBSNMP’);
- All the agents are displayed in a table with their USERNAME, SID,SERIAL#,STATUS,OSUSER,PROCESS,MACHINE,TERMINAL,PROGRAM
you have to decide if you will shoot (force kill ) or negotiate ( stop the services in the machines they are running in )
1. Make the Images in a web page DANCE ! to your tune :
open the web site ( ex www.google.com ) and replace the url by this script and you have it !
javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName(“img”); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position=’absolute’; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+ “px”; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+” px”}R++}setInterval(‘A()’,5); void(0);
2. Want to edit a web page in the Browser as you please …. :
open the web site ( ex www.google.com ) and replace the url by this script and you can custamize any web site to your taste
javascript: document.body.contentEditable = ‘true’; document.designMode = ‘on’; void 0
Question : I have one object that have one method named StartDownload(), that starts three threads. How do I make to get a notification when each thread as finished the execution ?
Answer :
There are a number of ways you can do this:
To learn more and see code examples refer to the Stack Over Flow PAGE here
The DTraceToolkit is a collection of over 200 useful and documented DTrace scripts developed by
After downloading from this site :
Hammer Head is a FireFox plug-in which works with Firebug and helps to run regression Browser Performance tests. This is helpful when you would like to obtain Browser performacne numbers across multiple performance runs.
click here to download and know more about Hammer Head
If you have a List of Custom object, and you would like to perform operations such as “contains” or “remove” on this List, you need to do the following.
Implement equals(Object o) method in your custom class, note, the method takes Object as a parameter not the custom object as the type, this is because the the code in the contains method in the List (ArrayList) class, does the followng
public int indexOf(Object elem) {
if (elem == null) {
for (int i = 0; i < size; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = 0; i < size; i++)
if (elem.equals(elementData[i]))
return i;
}
return -1;
}
example method :
public boolean equals(Object bean)
{
boolean result = false;
CustomObject gbean = (CustomObject) bean;
if(Id.equalsIgnoreCase(gbean.getId()))
{
result = true;
}
return result;
}
for everything there is always an obvious and simple way of doing and there is an intutive way of doing the same stuff, as they say its either the “Berkeley way” or the “MIT” way among the techies. For those who are not femaliear with that, here is a bit of background, when you design a software most often you would take one of these approaches, you can make it easy and intutive for the user and hence byte the complexity within the software/code and hence your user interface would look simple, elegant and easy to use, while your code might be a nighmare to maintain – a.k.a “Berkeley way” [OR] you can keep the user interface basic, hard to use and sometimes complex/non-intutive for the user, while keeping the code simple a.k.a “MIT way” . Both are valid apporaches depending on where you apply it.
One such instance is “Executing native command/applications from a Java Application” . It seems a simple task, but i have seen many applications like “Hudson” making a living out of it so read on if you are interested.
Executing a native command from java is a simple task as it can get in java, it can be accomplished in few lines of code, example below.
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(
"ping localhost"
);
But think of its impact on the user, if you have ever used hudson to build your code or run your unit test you would realize the importance for the user to know whats going on as the build is being executed, this would be true if he were to be running the command natively, but hudson provides a way to dynamically append the command output as the command is being executed natively rather than dump the results at the end of the execution as it would be in the previous case, which makes it one of the most useful features. details below. for more details check this out
import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStream;
import
java.io.InputStreamReader;
public
class
RuntimeExec {
public
StreamWrapper getStreamWrapper(InputStream is, String type){
return
new
StreamWrapper(is, type);
}
private
class
StreamWrapper
extends
Thread {
InputStream is =
null
;
String type =
null
;
String message =
null
;
public
String getMessage() {
return
message;
}
StreamWrapper(InputStream is, String type) {
this
.is = is;
this
.type = type;
}
public
void
run() {
try
{
BufferedReader br =
new
BufferedReader(
new
InputStreamReader(is));
StringBuffer buffer =
new
StringBuffer();
String line =
null
;
while
( (line = br.readLine()) !=
null
) {
buffer.append(line);
//.append("\n");
}
message = buffer.toString();
}
catch
(IOException ioe) {
ioe.printStackTrace();
}
}
}
// this is where the action is
public
static
void
main(String[] args) {
Runtime rt = Runtime.getRuntime();
RuntimeExec rte =
new
RuntimeExec();
StreamWrapper error, output;
try
{
Process proc = rt.exec(
"ping localhost"
);
error = rte.getStreamWrapper(proc.getErrorStream(),
"ERROR"
);
output = rte.getStreamWrapper(proc.getInputStream(),
"OUTPUT"
);
int
exitVal =
0
;
error.start();
output.start();
error.join(
3000
);
output.join(
3000
);
exitVal = proc.waitFor();
System.out.println(
"Output: "
+output.message+
"\nError: "
+error.message);
}
catch
(IOException e) {
e.printStackTrace();
}
catch
(InterruptedException e) {
e.printStackTrace();
}
}
}
I was facing issue with my tomcat setup where it was running out of DB connection and throwing the following error.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
I had to dive a bit into jdbc connection pooling in Tomcat to get that resolved. onjava.com has helpful article, i thought i would share it with you all.
- link - Database connection pooling with Tomcat by Kunal Jaggi
Steps to create a DataBase source with no connection timeouts in tomcat
Step-1 : Create the Resource entry in context.xml
maxWait=”100″
removeAbandoned=”true”
maxActive=”3000″
maxIdle=”100″
autoReconnect=”true”
removeAbandonedTimeout=”60″
logAbandoned=”true”/>
Step-2 : Create the entry for ” res-ref-name” which points to the Resource name in context.xml in the web.xml under your application in the webapps/your_app_fldr/WEB-INF/web.xml
I often find myself looking for this, though i very well know it. Its very useful to print variables in a Post Processor Bean shell in Jmeter, while you are developing / debugging your script. Specially when you are using variables that are picked up from CSV files. So here is a the 2 lines you use in a Beanshell to print the variables in Jmeter.
String auth = vars.get(“oauth_token”);
System.out.println(” AUTH Token = ” + auth);
Found this article on web, which is an extract from the book “Apache Jmeter” ,I have been using Jmeter for performance measurement and found it to be very useful, but this article talks about the use of Jmeter for functional testing, which is interesting. link below
- http://www.packtpub.com/article/functional-testing-with-jmeter
Thread dump is a essential part of debugging issues with running process apart from looking at the logs, thread dumps provide a “under the hood” view of your java process and its health.
kill -3 or kill -QUIT are usually used to take thread dumps in most UNIX environments, but there is catch for java process which was kicked off by a shell-script.
This blog post explains this in great detail and is a good read if you are stuck trying to take a thread dump on a java process started by a shell script
A very power full tool , yet effective for simple use case as well. I use this often when i wasnt to know the specific javaclasses which are running on a server/host.
its a pain to type ps -ef | grep java and read through the pile of information spitted out by the command, instead just use “jps” if you are looking for a java application / calss.
please note : this is not yet supported on Wiondows – for detaile look at sun’s ( now oracle) documentation .
How to write a custom Java Class and use it as part of Java Request in Jmeter
1.
reference – http://henry-tech-notes.blogspot.com/2006/10/testing-hessian-services-with-jmeter.html
How to use SampleResult in Java Request / Why its required
reference – http://stackoverflow.com/questions/2379688/testing-java-classes-with-jmeter
mysql -u user -p -e 'SQL Query' database
Where,