hennie louw

Ranch Hand
+ Follow
since Jul 03, 2001
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 hennie louw

Originally posted by hennie louw:
So it seems that they are more or less the same code.
The funny thinging is that I'm thinking wouldn't it have been more OO if String.equals looked like this.


I'd just like to point out some thing that I've noticed here. I still think that the way as above will be more OO but it will be slower.
If one uses the Arrays.equals(char[] Char[]) instead of duplicating the code you will be using one more clock cycle on the processor to check if the string is equal to one another. by the call to Arrays.equals(char[] , char[])
Now one clock cycle doesn't sound like to much, but what if you were to call String.equals in a for loop of about 1000000 time or so?
you would have to wait an extra 1000000 clock cycles if it did call Arrays.equals instead of just duplicating the code at an very small memory cost.
17 years ago
The reason why the Logger and Handler has a level is this allows mutiple Logger's to have the same handler and also mutiple handler's to the same logger.
Eg.
Situation 1: you have one Hanlder that writes to a file, and this handler level is set to ALL. You also have two Loggers that are set to ALL, now we chnage the one logger to only log WARNING logs because we know there is no unresolved problems for the one logger, but we need to get all the logs of the other logger. now both loggers can have diffrent log levels that are published to the same file.
Situation 2: You have on logger that accepts all logging levels, and two handler, one goes to a file and the other one to the console. now we can set one logger's level to ALL and have a detailed logging to file and the console handler is set to INFO, so in the console we only see runtime logs and no trace logging.
In both situations we could have used two logger and two handler objects, but with this design we can remove one of the hander/logger and save memory usage. and just Imagine if you had to set up 50 logger's with the same log message for 50 handler's that published to logs to diffrent locations, now we can do it with one logger and just 50 handler's , that saves us 49 objects form being created.
[ February 20, 2003: Message edited by: hennie louw ]
17 years ago

Originally posted by Jon Dornback:
I am reading in input from a socket, and need to compare it to a string value. which is faster:

thanks in advance,
Jon
[ February 10, 2003: Message edited by: Jon Dornback ]


Hi Jon Dornback
You could test it by doing a simple test like the following.

Here is the output I got on it.
Time for
method1 : method 2
0 : 20
0 : 20
0 : 0
10 : 0
0 : 0
0 : 0
0 : 10
0 : 0
0 : 0
10 : 0
0 : 0
Now here I stared noticing a few things.
A) if the byte[]'s are not the same then the Arrays.equals() method can be faster by first checking if the lenght of the two arrays are the same, if not they cannot contain the same data.
B) If the byte[]'s are large arrays and the first byte in each array differ the Arrays.equals() can stop checking them right there, but if they are simmilar except for the last byte in the array then it could take a bit more time to compare them.
Here is the code for String.equals()

Note 1 : This seems to speed thing up if the object being tested is not a String, but we know it is a String so this in not going to affect us.
Note 2 : This seems to be how I think they did it for in the Arrays.equals also, they first check the lenght of the String.
Note 3 : same as point B above... larger Strings will make more of a diffrence.
Thus I revised the code for the TestSpeed class to the following.

and Here is the outPut
Time for
method1 : method 2
10 : 40
40 : 30
10 : 10
20 : 0
10 : 10
10 : 10
20 : 10
10 : 10
10 : 10
10 : 20
10 : 10
Here is the code for the Arrays.equals();

So it seems that they are more or less the same code.
The funny thinging is that I'm thinking wouldn't it have been more OO if String.equals looked like this.
17 years ago
Hi all
I am currently busy with a small opensource project called Loadmax.
My problem is that I wish to have some of the modules, eg. admin modules, that are loaded be able to call core system methods by any other 3rd party module should not be able to do this.
Can anyone point me into the right direction of how I can do this,
Thanks
17 years ago
What You could do to kill this process is have all the instances of you application look for a file, this file can be any where, once it finds this file, it go's into it's shut down methods.
(but this way all the instances of you app will shut down once the file is created) thus if you know on witch port the instance is you want to shut down you can write that into the file and have you app read the contents of the file and if is matches the instances port then it should shut down and delete the file. (One thing here, you could create a lock file that must also be checked. if it exsists don't delete until the locke file is gone.), this way you dont have to worry about an error if an other instance is reading the file when you try to delete it.
Eg. you want to shut down instance listening on port 9085 and the "'shutdown" file should be /etc/shutdown.ME then to shut down the instance listening on port 9085 you would just do a
echo 9085 > /etc/shutdown.ME , and it should sut down.
=================================================
Also you could make each instance register it self with a global manager, and have the manager contain
info on the port that the instance listens to, and the via a command in eg telnet localhost, you could
shut down the instance running on port 9085
This would is not the best way to do it, but is seems to be OS independant way
17 years ago

Originally posted by Blake Minghelli:
All of our java apps run as daemons. We shut them down by creating a shutdown file (just a 0-byte file in a specified directory). Our apps are coded so that they periodically monitor for the existence of a shutdown file, and if they find one, then they know they need to shutdown.
Hope that helps.


At the current moment my systems also work in the way , but I am wondering if this is not causing I/O calls to the OS that will bring down performance
18 years ago
Hi All
I have been developing at few server side apps in java and would just like to know if there is any way
of starting an java application in a background process... (I have been able to do this with the process object ) but how can I invoke the app's shutdown procedure from the console??
A good exsample of this is the Tomcat JSP container.
it starts as a background process and even in windows
it does not have any dos prompt windows hanging around.
Any advice on this would be great
18 years ago

Originally posted by Jamie Robertson:
James,
on the application side, java will have no problems cleaning up after itself. You might notice a few pauses while the gc cleans up after itself, but things should run smoothly. However, the gc will not clean up your database resources. Without explicitly calling statement.close() and resultset.close(), the database cursor will remain open and you'll eventually run out of available cursors to query the database( SQLException: maximum open cursors exceeded ). So it's not really a java memory leak, but a database resource leak from sloppy database resource cleanup.
Jamie
Jamie



Hi all
Correct me if i'm wrong but primary data types like
eg int. Do not get cleaned up by the gc and is placed in the stack memory (and not in object memory), so when you have no reffrences to an int value that you used it is automaticly free to use again.
the reason i'm asking is simply because it you are using a jdbc method that returns a ResultSet but you are Ignoring the returned object the SQL command was most likely a update or some such.
Would it not be better to use the method executeUpdate(String sql) witch returns a int and handles the closing of any ResultSet's inside itself
I can think of one reason why you would execute a select satement and not use the ResultSet in some way
18 years ago

Hi Rupinder
I was just wondering, the way I understand this is the user must enter numbers into these TextFields and then click on the ok button, but why are you then adding action listener to each TextField ? if the code in actionperformed() should only be executed once the user presses the ok button this will never happen. because you have no action listener on the button , and from what I can see, it will execute for each key pressed in any of the Fields.
[ August 27, 2002: Message edited by: Thomas Paul ]
18 years ago

Originally posted by Max Habibi:
Hi Hennie,
Looks like I misunderstood your question. Ok, as to the answer you really wanted:
You shouldn't have to do anything: the new process should be indepentent of the spawning process. I know that it works this way in win2k. I would suggest a simple test. I would also suggest using java in silent mode.
Best regards,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Hi
Thanks for the info bu what do you mean with "java in silent mode" ?

Originally posted by Max Habibi:
Hennie,
I'm not sure I've been clear. Terminiating the parent process(the one that had the rT object) will cause the Thread to run. That Thread, in turn, will terminate the child process. So the answer to your question is yes, assuming that the jre on that system is bug free.
This should be easy enough to test.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Max,
Sorry if I have been stateing my problem wrong, what I want is for the child process to keep running in the background even after the main program has stoped, this app is a basic start and stop script for the child process that is the actual server app
So wat I want is for me to log on to a machine and
run "java [mainapp] start" and the have the console return and the child process running , log off and mabe over 2 hours or so long on again and run "java [mainapp] stop"
Please let me know if there is still some sort of misunderstanding
Thanks for the info so far( just what i needed for a diffrent app im working on )

Originally posted by Max Habibi:
your runtime object, rt, has a method called addShutdownHook. The paramater to this method is a Thread object, which gets run before the program exits. Thus, you would put clean up code inside of a thread object's run method, pass the thread to the addShutdownHook method, and all would be well.


Hi Max
i understand this but what i am asking is how do i get the jvm of this background process to invoke it's shutdown hooks??
Let say we run it on linux, by typing
killalll -9 java
will this not forcefully terminate the process or will it send the process a termination signal and allow the jvm to move through its normal shutdown hooks ???
Also can anybody tell me if by starting the process in this way will the process keep runing on a machine after i've logged off??? like tomcat does or will it terminate ?
Please help with this asap
thanks
Hi all
I've got a litte problem.
I have an ap that runs ans starts another java app as a daemon on a server
I am starting the daemon app in the following way

my questions is:
1. Will this process keep runing on the unix system after i log off (can use nohup or anything like that, will also need to run in windows)
2. How can I shut this process down without killing
the process (meaning invoke it's shut down sequence, the app is handling request and if i just kill it the request queue will not be dequeued )
Any help in this would be very great
Hi all
I am having trouble with a ap that needs to read
data from a com port and do things accordingly, but the ap also needs to the System.in stream for a ctrl+Z char and exit on that.
The problem is that the app doesnt seem to read the streams correctly
here is some sample code

Now what should happen is that once i press a key the system should print the Uncode number of that char to me on the screen, this works but only after I have pressed enter and the kbInput.read() reads a
<cr> ??? , this does not seem to me to be correct. how can i get the kbinput.read to read without waiting???
thus if there is nothing it should return a null value
18 years ago
You could try the Java Comm API
more info at

Com % /dev/ttyS0
18 years ago