Win a copy of Spring in Action (5th edition) this week in the Spring forum!

puff li

Greenhorn
+ Follow
since Jul 28, 2010
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 puff li

Hi,

I am writing multithreading Java program. I have one thread waiting for another thread to reach some point in an infinite loop. However, after some iterations, it will never reach that same point again. It seems it stucks, but its state is still runnable. Can some one explain why it is like this? Is it possible the JVM will never execute a thread which is busy waiting or the OS will stop it? I debugged the program for a day but still can't figure out what is wrong... Please help.

Thanks in advance.
Hi,

I am using Apache POI to access MS Excel. I am an 5 * 10 Excel data. But the getLastRowNum() method returns 19... and in the 6th row the method getLastCellNum() method returns 3.. and NullPointerException.

Also, if there data is a number, say 15, if I use getCellValue().toString(), it will display 15.00. If I change the cell type to string type, if I use getStringCellValue, if the data is 27.95, it will display some weird value like 27.9500034..


What is wrong??? Thanks.
7 years ago
Thanks for reply. Can you tell why we can't treat binaries as string. It is corrupted. But it's there. Why can't we use replace? I know POI but find it complex...
7 years ago
Hi,

I am trying to replace a word in a MS word file by another word and then save the modified version. Here is how I am doing it now:

I read the word file as bytes and construct the string by bytes and replace the word. Then I write the string to another file. The word can be found and replaced. But when I write the string back to a word file, MS word can't recognize it. It seems the file is corrupted.

I just replaced a word. I know I initially read in binaries. But I write them back as well. I don't know why MS word can't display it.

Please help. Thanks in advance.

--
Simon
7 years ago
Yes, you are right. I should use boolean...
Oh, I found the bug. The Boolean object returned by this statement is null. I forgot to initialize it
Thanks anyway
Thanks for replying.

Below is the information printed



It's all from this statement. ThreadId is not constant. It is printed by
etc
And the semphore infomation is printed:

It's not null.

By the way, getSemphore() get the semphore object from a static hashmap from CheckPoint class. The hashmap is initialized in the class as static field. Other threads put key and value into it.
Hi,

This statement



continuously throws NullPointerException

getSemphore() is a synchronized static method of CheckPoint and isBeforeWait() is a synchronized method of a Semphore object.

I am quite sure Semphore object is not null and I use Class.forName to load CheckPoint class before this statement and after the exception I print out the Semphore object, it's not null either. How come it throws NullPointerException? I'm driven mad! Please help!

Thanks.
Then, if a thread A calls B.join(), should A be in wait state or block state?
Hi,

What is the difference between wait and block state of a thread?

Thanks in advance.
Oh, I know. I should use /usr/bin/java since java program don't know environment variable..........
8 years ago
I want to run a java program from another one using getRuntime().exec(), but it won't work. Here is the code:



Here is Test2.java


The file is never created. I don't know why. I suppose should be run from command. But I don't know how.
Thank in advance.
8 years ago
I know how to start a thread. My problem is to replace normal way of starting a thread with the way of Javaflow. So I need to look at the source code and replace obj.start() with Continuation.startWith(obj). Since other classes can also have the start() method, I can't simply find start() in source code and replace it directly. I need to make sure the obj extends Thread. The situation is complicated because you can return a Thread object from a function (ie. a.returnThread().start()), then I have to make sure a.returnThread() returns an object of Thread.

Am I clear?
8 years ago
Hi Namam,

Thanks. I think I didn't make myself clear. I wanna write a program to do this automatically. I have a bunch of source file to process.
8 years ago