James Zhang

Ranch Hand
+ Follow
since Sep 06, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Zhang

Thanks so much for your comments, Ernest! I changed the buffer size to 350M and adjusted the heap size, then it works! Your insights are really useful!

--James
[ January 23, 2007: Message edited by: James Zhang ]
17 years ago
Probably I am processing large files most of the time, I got another problem on the jvm memory management: I am trying to read a large file (320M) into memory to be processed later, so I wrote the following program:

public class Test2 {

public static void main(String[] args) {
String filename = "c:\\work\\data\\testfile1.xml";
int size = 20000000;
char buf[] = new char[size];
try {
Reader reader = new BufferedReader(new FileReader(filename));
StringBuffer buffer = new StringBuffer();
long total = 0;
int num;

while ((num = reader.read(buf, 0, size)) > -1) {
buffer.append(buf, 0, num);
total += num;
System.out.println("Total chars read:"+total);
}
reader.close();

} catch (Exception e) {
e.printStackTrace();
}
}

}

The result is as following (jdk is 1.4.2):

C:\work\workspace\test1>java -Xmx800M test1.Test2
Total chars read:20000000
Total chars read:40000000
Total chars read:60000000
Total chars read:80000000
Total chars read:100000000
Total chars read:120000000
Total chars read:140000000
Total chars read:160000000
Exception in thread "main" java.lang.OutOfMemoryError

I have > 1G physical memory in the machine, so this should not be a problem at all. Changing maximum heap size seems not helping at all! I also tried to change the buffer size from 20M to 20K, but it doesn't help at all.

Anybody knows why I could not allocate 320M memory when the heap is much bigger than this? Any suggestion would be appreciated!!!

--James
17 years ago
Thanks for your valuable comments, Jim and Ilja! I I really appreciate all the helps! We have already used -Xmx2G when starting JVM but seems not helping too much. As your guys pointed out, it is not a good idea to run GC in the codes. My program is just a testing for the GC functionality because I was suspecting that the GC process was not started in our application. Probably a better way is to use tools like JProbe to analyze the memory usage for the application, which is what I am trying to do next.

Again thanks guys!

--James
17 years ago
By the way, I also tried using SoftReference and WeakReference in the array list. The result is a little better than to add string directly to the list, but still there are about 1/3 of the allocated memory uncollected.

--James
17 years ago
Thanks for your replies, guys! The reason I am doing the test is for my current project, which processes a large amount of data in memory and always ends up with OutOfMemory exception. One scenario is that I have a list of 830000 objects and need to generate a result string from those objects. One approach I was trying to avoid the memory problem is to free the previous processed objects before doing further processing, but it didn't work. That is the reason why I played with the freeMemory() method to see how GC works for my JVM. I have set the parameter as -Xmx2G (my machine has 3G physical memory) but the problem is still there.

Back to the original program, I believe GC has actually started when the main thread is sleeping (If the statement System.gc() is commented out, you will see that no memory has been collected at all in result). It looks to me that one round of GC does not finish all the work, as only half of the allocated memory is collected. Does anybody know how to make GC collect more memory?

Thanks again for your time!

--James
17 years ago
Hi,

I am trying to use the freeMemory() of Runtime object to determine the available memory in JVM, so I wrote a simple program to allocate some memory, then free them and call GC to notify system to collect them. Ideally, most allocated memory should be collected by GC. However, every time there are always about half of the memory uncollected, and I don't know if it is the problem of freeMemory() or the GC process! Could someone please take a look at the program below and tell me why the result?

Thanks a lot for your help!

I was using Eclipse to run the program and the result was like:

Space used:6091568
Uncovered space:3033752

[ added code tags - Jim ]
[ January 18, 2007: Message edited by: Jim Yingst ]
17 years ago
I don't know if this problem has been discussed before or not, but there is my problem: I have two actions, action1 and action2, with corresponding forms (form1 and form2) and jsp files (jsp1 and jsp2). Both jsp1 and jsp2 contains a submit button, so I defined the same property "submitButton" in both form1 and form2 for the button.

The process flow should be that user clicks submit on jsp1, action1 will do some work, and then forward to action2, and action2 will do some initialization work and display jsp2. The struts-config.xml would look like:

<action path="/action1" scope="request"...><forward name="submit" path="/action2" /></action>
<action path="/action2" scope="request"...><forward name="submit" path="/action3" /></action>

The problem is that since I give the same property submitButton for both form1 and form2, so when action1 forward to action2, action2 always find the property submitButton of form2 to be not null! Therefore, action2 forwards again to action3 just like user also clicks the submit button on jsp2!

I know the problem will disappear if I give different names for the submit button in form1 and form2, but this is really not a good workaround.

Does anybody solve similar problem before?

Thanks in advance,

James
17 years ago
Did you include the COMPLETE error message in the post? It seems to me that the root error is not shown there.
Recently I got a weird error with the SQL tag of JSTL. We are using JSTL for simple database table maintenance and it worked fine before. I don't know what is changed but now we got sql error ORA-17004 (Invalid column type) every time when user tries to insert a new record. However, if all the form fields are filled in, there will be no problem. Does anybody have similar experience before?

By the way, We are using <sql aram...> and <sql ateparam...> to pass the values to the Sql statement, but I checked several times of the values passed in and there should not be any problem.

Thanks in advance!

--James
18 years ago
JSP
If you want to use a certain value as the default selection whenever the form is displayed, set the value for your form property "inmateSite1" inside the method reset().
18 years ago
One way to do it is to define the properties in your struts form for the values and labels. For example, you can define a property called "values" as a collection of the desired values and another property called "labels" as the desired labels for your struts form, then the following codes in your jsp file should display the list:

<html:select property=...>
<html ptions property="values" labelProperty="labels" />
</html:select>


Good luck!
18 years ago
I am looking at one application developed with Struts 1.2 and velocity, and find some unusual actions like below:

<action path="/login" type=...>
<forward name="success" path=".portal.home" />
</action>

I have never seen a forward path could start with '.', but it works here! Does anybody know where to find the corresponding file/action for ".portal.home"? There is no such mapping in web.xml or struts-config.xml.

Thanks!
18 years ago
I am kind of new to JMX, but could somebody elaborate the advantages of using JMX over other technologies like EJB? I have read the tutorial and concepts from Sun's website, and it seems to me that the whole concept of JMX is to wrap one application or resource as MBean, register it with JMX server, and then invoke the corresponding methods from somewhere else. However, similar steps have already been taken by EJB.

Furthermore, if the whole application is on one server, which is the most common scenario, you can easily pack the resources or sub-applications as regular Java Beans, and then use them directly without worrying about the JMX server.

Probably I am just not clear what problem JMX is trying to address.

Thanks in advance!

James
I am kind of new to JMX, but could somebody elaborate the advantages of using JMX over other technologies like EJB? I have read the tutorial and concepts from Sun's website, and it seems to me that the whole concept of JMX is to wrap one application or resource as MBean, register it with JMX server, and then invoke the corresponding methods from somewhere else. However, similar steps have already been taken by EJB.

Furthermore, if the whole application is on one server, which is the most common scenario, you can easily pack the resources or sub-applications as regular Java Beans, and then use them directly without worrying about the JMX server.

Probably I am just not clear what problem JMX is trying to address.

Thanks in advance!

James
18 years ago
Thank you so much for the help, pascal! It is the problem!