Tilman said:
[The aspects of the OP I'll address aren't EJB-specific, so I'm setting
F'up2 cljp.]
In message <
[email protected]>,
exquisitus wrote on Sun, 27 Feb 2005 15:20:33 +0000 (UTC):
I'm writing an engineering library in a Java package. The package is
very simple. There is no constructor
Yes, there is. Even if you didn't write one.
(since I do not need to do any
global initialisations etc at startup). All the methods in the
functionsa re declared as static public (defining the API of the library).
Unless you keep no state in your class, this static approach is almost
certainly inappropriate.
It is possible that I will write an JB wrapper around this library to
creat an EJB bean - in the near future. I am wondering if declaring my
methods as static may cause problems when it comes to turning the
library into an EJB - in particular, I am worried about re-entrancy
problems (the library is currently NOT thread safe). Is this a warranted
worry - or am I worried about nothing?.
If you say your class isn't thread-safe, that would seem to indicate
you do keep some state. In that case, yes, you should worry. If you
don't keep state, there is obviously no state to corrupt, and therefore
no need to worry.
Writing stateful classes in a purely static way is in many ways
analogous to global variables, and is generally just as wrong, IMO. Why
don't you want to have separate instances of your class? Let me widen
the scope of that question a bit: Having read some of your other posts,
I cannot help but wonder why you are so determined at circumventing
object-orientation in an object-oriented language. Can you explain your
motives in this regard a little bit?
Hi Tilman,
Jeez, you Java guys are a bit *touchy* - aren't you?. I can't help the
fact that I am from a C/C++ background and I have only recently started
taking a serious look at Java (I have ignored Java in the past - because
it was simply too slow for the number crunching stuff that I normally
work on). I am trying hard to understand why things that are so
straightforward in C/C++ are either absent or (appear to be)
'workarounds' - case in point, enumerations, template classes, variable
length arguments and pointers (even safe pointers) - but ofcourse I
can't mention the 'p' word here can I ?
Seriously, Java has some good things (a lot of good things) going for it
and thats why I want to get up to speed with it and write some code. I
believe the best way to learn a language is diving in and getting your
hands dirty with some actual code - and that means, sometimes asking
"silly" questions. If I ask a question, its because I have struggled
with it for sometime, done a google search, not come with anything
useful and I genuinely would like to know what the problem is - it is
not to start a flame war of "my language is better than yours" or any of
that crap.
You mention that I am trying to write in a non-OO way. Well I dont see
it that way. What was the point of pointing out that I *have* a
constructor (everyone knows there is a default constructor when you
don't provide one). There was no need to waffle and state the obvious.
What I am doing is quite simple (at least it should be). I ahave a C++
library that I am converting into Java, and would like to convert the
library into an EJB at a later stage. I feel that this exercise will
teach me pretty much most of what *I* need to know about Java - at least
for the time being.
The question I am asking here is quite straightforward. I have a simple
library - I have implemented this as a singleton pattern so that there
is only one instance of this 'number crunching engine'. All methods in
the exposed API are static. Since I haven't read the entire tomme about
EJBs I just wanted to know if I needed to do anything special to the
library before wrapping it up as an EJB. It is just a collection of
engineering functions - no state is being saved. All I am asking is that
do I need to do anything to the code before turning it into an EJB - I
would have thought that was a fairly straightforward unprovocative
question to ask.