I have a routine I wrote a long time ago that use primitive arrays -- int a[][] , String sa[], double d[][]. The ones with [][] are really ararys of arrays not 2d arrays (x-y).
My question is are these synchronized so different threads have to wait their turn.
How might I extend the [][] array of arrays as well as the simpler a[] and sa[]?
I've looked at Vectors (synchronized) and the others (non-sync'd). How might one handle the array of arrays with Vectors?
I'm preparing a short sample to add to this and should have by tomorrow morning.
Arrays of arrays belong in C, not Java. You should use one of the various collections, in your case one of the synchronized collections like Vector. If you put arrays into a Vector, viola! you've got an array of arrays only object oriented. (In general you're better off staying away from native types entirely except when they're required for low level interface stuff.)
Oh man that's some ugly code in that attachment. It's basically just a C module.
I'm learning a great deal from what you supplied. Pretty simple once it was coded. I need to get a better text (Core Java2 version 1.5), study it and work on this more. My code was developed back on a PDP (model 8 or 11 - can't remember) and the c version wasn't very versatile.
Is your code synchronized/thread-safe? Core Java says that only Vector is synchronized and the others can be by adding extra code in each routine.
I'm not sure what you mean by thread safe, this is not a multi threaded application is it ?
If multiple simultaneous processes were to access this, also for element deletiion, I
would have wrapped the access in one synchronized method using an additional
access type parameter.
Thanks for the response. You've bailed me out before.
I use the ugly C code in a number of algorithms and some are multi-threaded. That was one of the reasons I started this thread. Could you easily show me what is needed for the synchronized version?
I have already insert the code for other data types and it seems to work well. I've even made an interface to link this to the old code replacing my ugly code.
Thanks again.
RON C
The part about Texas was for Ray326 as I didn't pay attention to whom had sent the new code.
The sync will have to be for the methods that add and remove elements, so you could
make one synchronized method called updateGP that took three parameters and
handled both add & remove;
Code:
public synchronized void updateGP(int updateType, int name, Object value) throws GPException {
.
.
}
This method could be used for both add and remove operations, for the remove
operation the last parameter would be null (and that would be the only one to
throw a not-found exception)
I did realize that you were not the one who had responded and apologied to SJalle.
I also thanked him.
You guys are real helpfu even thoigh my code is real ugly. That ugly code might be older than most on this site as I coded it sometime around 1970 - maybe earlier for PDP 8 or 11 and bastardized Fortran and C code. I can't remember which machine. I was a researcher who needed some table lookup code and we kludged tht together.
How about 45000 lines of fortran code with lots of parameterless subroutines
and the whole variables ballgame stuffed into one big fat common area, in
order to calculate the mass balance on the Ekofisk oil field... ?
Bookmarks