Siva Prasad

Ranch Hand
+ Follow
since Feb 22, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Siva Prasad

Let's say I've the following code segments:

In case of [a] what will happen if some thread currently holding the object of the method update1() and returning some value from that method. Does it release the lock upon executing return?
In case of [b] assume that one thread (say A) held the lock of the object of the method update2(). After executing someMethod() does the thread A hold the same lock or release it? Assuming that someMethod() is also synchronized and is in the same class, What happens then thread A still be able to execute the body of someMethod()?
Finally is it safe to return from a synchronized block or method?
Thanks
Prasad
Hi
Can anyone give some pointers to character encoding in Java.
I know java uses unicode. But I want to know more internatiolization.
Thanks
sivaPrasad
22 years ago
Hi
It depends on what exactly you are trying to do!
If you simply wants to read contents of a file, you can use RandomAccessFile no need to use any other classes along with this.
You can read any data type with this class. It has wide range of read methods.
HtH
SivaPrasad
22 years ago
I'am facing a wierd problem. read on...
When I try to run the following code
I get different result with default encoding on both Unix and NT.
Can any one shed some light on this?
by the way I am restricted to use only Java 1.2.2
I know JDK1.3 and beyond JDK come with character encodings including UTF-16 etc..
My question is ...
why I see diff characters from getBytes() method for special characters in between 0-255?
Thanks
s:vaPrasad
Here is the code :

[ June 27, 2002: Message edited by: Siva Prasad ]
22 years ago
Please note also that, these clients are launched from different shells. So its difficult to do with fg command.
Do we need to write some code in our client to dump the stack or is there any other way?
22 years ago
Hi
on Unix,I am running 10 java clients contacting with one java server.
Anytime, if the client hangs/freezes/stops sending requests to the server, then how do I get the stack of that client process?
Also what are the other command with which I can trace any java process?
Thanks for your help
sivaPrasad
22 years ago
Ok here is the code I wrote for this.
this takes two arguments
1 - string to find
2 - filename


You can have a look at indexOf methods from String class.
HtH
22 years ago
If so, is it safe to do this way?

public class ThTest implements Runnable
{
public static void main(String[] args) throws Exception
{
new ThTest().runThis();

}

public void runThis()
{
Thread m1 = new Thread(this);
Thread m2 = new Thread(this);
Thread m3 = new Thread(this);
m1.start();
m2.start();
m3.start();
}

public void run()
{
System.out.println("It's me ");
notify();
}
public void myFun() throws Exception
{
wait();
}
}

I get the following when I run this:
It's me
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at ThTest.run(ThTest.java:25)
at java.lang.Thread.run(Thread.java:479)
It's me
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at ThTest.run(ThTest.java:25)
at java.lang.Thread.run(Thread.java:479)
It's me
java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at ThTest.run(ThTest.java:25)
at java.lang.Thread.run(Thread.java:479)
Hi
Problem in your code lies in the calendar objects you've created.
If you dont mention any arguments while creating these GregorianCalendar objects, those will be treated as those objects which show the current date and time.
so the code should look like this :

I hope this helps
cheers
sivaPrasad
22 years ago
Hi
Try to use DateFormat class. Its pretty useful when you want deal with Date/Time stamps or both.
Cheers
sivaPrasad
22 years ago
Hi
If you read the description of the method length(), it clearly says that the return value of length() will be 0L(long value) if it cannot find the specified file name on the disk. So in your example there may not be such file called Test.txt
If you need more clarification, then use exists() method.
cheers
sivaPrasad
22 years ago
Hi
Its very much possible!
I would use the following classes to achieve this:
String
StringBuffer
RandomAccessFile
Cheers
sivaPrasad
22 years ago
How about this?

But Angela, instead of asking for the code straight away, I think you should toy with those IO Classes we have in java.io.*
They are very interesting to play with.
cheers
Siva Prasad
22 years ago
Hi
a) As Prabhat mentioned, usually there will be many security issues come into picture if you want to do anything on the client side. One must keep this in mind, whenever they write any applets or any java related stuff which deals with browsers.
b) You can use writeLine() method from the class RandomAccessFile to write any lines into a file. This feeds in carriage returns at the end of each line.

cheers
Siva
22 years ago
Shame me!
Yes A and C are right answers
Siva