php^java: corporate adoption

–my own theory
For now, java looks like longer-living than php but so did perl vs python, so did apple vs PC java/C++ have more /depth/ than php, perl, python — more to learn, more to explore, but that’s because developers contributed to them and put them to many many uses. java is now used to solve bigger problems than php, but in an earlier era of java vs c++, java was only for applets. things could change fast once developers gather around php. Look at linux vs Solaris.

PHP could expand to embrace java features. Look at mysql vs oracle, c# vs java, or java vs c++.
The big power groups:
– open source developers,
– corporate backers like IBM, Oracle
– high-profile adopters,
– other software supporting each other

rule@try-catch-finally execution order { catch block

— In the absence of finally —
[ try3 = try block in unfinished method #3 on call stack ]

When catch3a (among catch3b, 3c) is triggered by a *propagated* exception pe,

* we know (since it’s propagated) that try3 must have called a try4 which threw pe, and
* we know that upon catch3a completion, the statements following catch3a run, not those following catch4

What if there’s a finally? Finally can easily derail this rule. Let’s hope that finally doesn’t return, exit, break/continue or throw.

rule@try-catch-finally execution order: cover-up

-> catch?
-> finally
-> propagate
-> catch?
-> finally
-> propagate

Upon throw, jvm tests the innermost catches. Before propagating, the innermost finally runs. See P475 [[ thinking in java ]].

Propagating = searching for a catch at the next level.

In fact, finally has the capability to suppress the uncaught and to-be-propagated exception by throwing a cover-up exception. See P477 [[ thinking in java ]]. Similar to a county communist official covering up a murder case scheduled for escalation. This is the only guy we know with the power to cover up a murder case. shows a clear example “suppressed exception”.

Q: if a finally says “return”, will the method return normally, leaving the uncaught exception covered up?
%%A: I think so. see earlier blogs.
%%A: I think P 56/P65 [[java precisely]] says no the uncaught exception would propagate out

jdbc conn pool — swimming pool

there’s some logic/intelligence involved in pool growth/shrinking, conn reclaim … That logic is somehow provided by the servlet container, within the same JVM. I think it’s provided by the “swimming pool manager”.

“container-managed conn pooling” is a common phrase. Servlet Container maintains a pool of connection objects — each a chunk of memory.

A primitive implementation is a hashmap in the container’s memory, A hashmap of physical (ie in-memory) PooledConnection objects.

“swimming pool manager” is a boundless (can’t bypass) wall between the servlets and the pool of PooledConnection objects, and exposes to the servlets essentially 2 methods — getConnection() and closeConnection() . Not sure about the method names. Reacting to these calls, the swimming pool manager hands out or reclaims a “physical” connection from the servlet to the pool.

“swimming pool manager” is the single “spokesman” and single point of access of the pool.

“swimming pool manager” is request-driven. I think a class will “send it a message” by calling poolManager.getConnection() or poolManager.closeConnection()

In Weblogic, a swimming pool manager (the hashmap of conn objects) may need 2 helpers — dataSource and a pool driver.
* i think u need to specify the driver in your jdbc calls
* You can choose to use dataSource when obtaining a connection from the swimming pool manager.

perl constructor

constructors can be named “new” or something else like “spawn” or “new2”, but probably never identical to the classname. From now, let’s assume it’s “new”.

A constructor is technically just another class[1] method. Technically the only(??) difference I can see is the last “return bless..” statement.

[1] A perl constructor is usually a class method, seldom an instance method.

rule#55@try-catch-finally execution order–suspension

“exit-type statements (exit, return, break or continue…. ) in a catch{} are /suspended/ until finally runs its course.”

think of catch{} as a naughty kid. jvm will let catch{} run its course right before catch{} attempts to exit the try-catch-finally. At that point, finally{} takes over. As a good care-taker, finally{} usually [1] keeps the “exit-plan” of catch{}.

[1] see other posts on this execution order.

Q: How about a throw instead of an exit-type?
A: “If a try block throws an exception and the catch block propagates the exception (throws it again), the finally clause will still execute. If the finally clause executes a return statement, it overides (covers up) a thrown exception so the exception will not be thrown; instead the return will occur.”

A: look at the java precisely example 90

Q: what if finally /attempts to/ override that exit-type statement?
A: it will prevail.

A: look at the java precisely example 90

struts vs spring, component-by-component

1) Struts Actions Are Roughly Spring Controllers

Actions are abstract classes (extends Action@@) and Controllers are interfaces. In order to be configured as a Spring MVC controller, an object would need only to implement the following method:

ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response); # pushmail

the simplest intermediary transition step from Struts to Spring is to rewrite Actions so they implement the Controller interfaces and reuse the existing code. This allows incremental removal of all the Struts dependencies while the application remains operational.

Some of the supplied Controllers match the more specialized Struts Actions with which you may be familiar. For instance, if you use DispatchActions, MultiActionControllers and the more elaborate AbstractWizardFormControllers will be helpful. About a dozen different Controller implementations come with Spring MVC, so it is well worth exploring their purposes and how they can replace your Struts mechanisms.

2) ActionForwards -> ModelAndView

closest component in Spring MVC to ActionForward is the ModelAndView interface. Spring Controllers return implementations of the ModelAndView interface, which, like a Controller, can be custom implemented. Or, if appropriate, you can use the ModelAndView implementations supplied by Spring MVC.

As the name implies, ModelAndView objects have Model and View components. Model components contain the business object to be displayed via the View component. ModelAndView implementations may not have any Model components included. They may simply forward into some form of an actual View component (JSP, XSLT, Tiles, HTML, XML, etc.). As with Controller implementations, I strongly recommend researching Spring MVC-supplied implementations of the Model and View interfaces and View Resolvers.

*) afbean (actionForm beans) have no direct counterpart

*) spring taglig is much smaller than struts 4 taglibs (html, logic, bean ….)

*) ->

*) struts “action path=..” -> simpleUrlMapping to map a request URL to loginController

*) struts “forward name=..” -> viewResolver to translate a logical view name to a URL

*) struts-config.xml -> yourDisplatcher-servlet.xml (WAC4DS) + auxiliary config files

*) execute() -> handleRequest()

java always pass-by-value

A ref-type argument is passed by value — a copy of the remote-control, pointing to the same object

Once you point “critique_arg” to a new object, this method loses contact with the original critique object ] the caller method.

private boolean recordFault(Critique critique_arg, String brokenSlot){
String message = “Required slot ” + brokenSlot.toUpperCase() + ” missing.”;
critique_arg = new Critique(Critique.Severity.Critical, 0, slot, Critique.Type.ORDER);

By the way, the original object will get garbage collected if the variable in the caller method also gets assigned a new object.

real&&rare value-add to developers@weblogic

Some developers have 3-5 yeras experience on weblogic but offer no valud-add relative to “thinking” develoeprs coming from, say, websphere backgrounds. Value-add ranked in terms of value:

* 1) insight into weblogic trace logs (=> tuning, TR). Each app server’s developers have their preference what to log. Perhaps a neglected aspect of J2EE standardization.
* key limitations of weblogic vs websphere, jboss. There are probably dozens of limitations but real veterans know a few serious ones
* weblogic server tuning
* monitoring (=> tuning, TR)
* weblogic cluster
* JRockit Runtime Analyzer and esp. mem leak detection
* weblogic support for web services — different from other vendors

other value-add without ranking:

* weblogic domain
* weblogic deployment tools
* weblogic JNDI idiosyncrasy
* AR
* dev^production mode
* when not to use weblogic jms
* when not to use weblogic conn pool
* idiosyncrasies of weblogic thread pool

Fwd: commit/rollback ] jms pub-sub means …

when the jms tx mgr executes a commit
– each msg produced in the tx is commited to the queue@@
– consumed msg is removed from queue@@
And the consumer must send ack to broker

when a rollback takes place
– msg produced in the tx is destroyed@@
– msg consumed in the tx is put back into the queue@@
And broker must /redeliver/ it (push instead of the point-to-point pull)

Fwd: UBS iview q

Q: how do u implement caching when a query always returns 5000+ records, but you don’t know when it may change
A: cache invalidation?

Q: Have you implemented tomcat cluster?

Q: Oracle …. have u done some backup, tuning@@

Q: dev methodologies

Q: sugg an AR for a reporting system with 200 users/day. What DB? what app server?

perf tips4pushmail

based on

  • worker threads: Maximize thread lifetimes and minimize thread creation/destruction cycles.
  • Use a separate timer thread to timeout socket operations
  • my EJB: Use the transient keyword to define fields to avoid having those fields serialized. Examine serialized objects to determine which fields do not need to be serialized for the application to work.
  • Start producer connection (dispatcher) after you start consumer (worker).
  • Control transactions by using separate transactional
    session for transactional messages and non-transactional session for non-transactional messages.
  • Choose non-durable JMS wherever appropriate to avoid persistence overhead.

in java, "inaccessible" means

q: a private (static/non-static) member priv2 in class P is “inaccessible” in a client class C. Exactly what does it mean?

A(short): “class C can’t mention priv2 “

A: “a statement in class C will trigger a compile-time error if it mentions priv2 “

I think for each method call the compiler identifies
* the target-object (“target-class” for static) [1]
* the source-object of the caller method — upstream on the call stack

[1] but the target object is determined at run time by dynamic binding (– polymorphism) even if you prefix a variable (“remote-control”) in front of the method name. OK you are right about
* compile-time access checking
* run-time binding.

Here’s another case for IS-A and method-overriding rules. The long explanation is complicated. Let’s try a short explanation. What the compiler says actually holds at runtime, because the overriding version (that actually runs [2]) is as accessible as the overriden version.

[2] that binds to the method name at run time. “runtime binding”

composite prikeys includ`nullable columns@@ NO

Remember primary key must be unique.

If one part of a composite-key is null/unknown, the entire composite-key’s value becomes unknown. => Every member of every composite prikey need a not-null constraint. If you attempt to create/define an offending prikey, i think somehow the DB server will refuse.

In general, if either of the 2 things you compare is unknown, result is unknown. Remember “null AND true = null”, “NOT” applied to a condition with null value -> null?

Non-comparable => can’t test uniqueness

treemap of treemap – UBS IV

a Google-style question asked over the phone

Q: simultaneous producers and consumers, in multiple JVMs, connecting to your “string manager”, sending various strings or requesting all strings of a particular length. When returning all 3-char strings for example, the strings should be returned in dictionary order. What’s your data structure and synchronization in the string manager?

(Now I think) A: a mega-skiplistMap of micro-SLMaps. The mega-map uses string length as keys. Micro-maps use actual strings as keys and “recurrence” as value.

A mega-vector won’t do because we may have only strings longer than 1,000,000. However, in reality we always can (and therefore should) get some knowledge of the input data distribution, otherwise the design would be hopefully unoptimized.

A mega-HashTable will beat the mega-SLMap in insert/delete/update/read performance.

Q: What about range-selects like “give me the 15-char group, 14-char group … till 1-char
A: I think mega-SLMap would beat mega-hashmap???

Q: what if the input consists of english words?
A: set up micro-slMaps for Group 3, for G4, G5… These will get the most hit. Put all of them in an fixed-sized array, which should entirely live in register. Longest words are probably 20 (“internationalization”)

open/fetch/close cursor ] pl/sql, part 3

Lesson 1: For a regular loop
declare/ %ROWTYPE / open / fetch..into/ %NOTFOUND / close

Lesson 2: For a cursor for loop: DECLARE / FOR / END_LOOP

— %ROWTYPE omitted
— OPEN omitted
— FETCH..INTO omitted
— %NOTFOUND omitted
— CLOSE omitted

– – – – Now a real example: – – – –

FOR undeclared_var in cursor3 LOOP
-- use the var

strongly^weakly typed

Most complex software favor strong typing. I feel it’s not all due to ignorance, inertia, corporate politics or the marketing machine. Some brave and sharp technical minds ….

I think large teams need clean and well defined module-to-module interfaces. (module ~= class) A variable (mostly a pointer to a chunk of memory) should have well defined operations for it.

The precision comes with a cost — development time, inflexibility … but large teams usually need more coordination and control. At the heart of it is “identification”.

In the military, hospitals, government, and also large companies, identification is part of everyday life. It provides a foundation to security and coordination.

At the heart of OO modelling — translating real world security policies into system built-in rules. Strong typing = precise type identification.

2min guide2rbac]solaris10

–5 things about rbac-priv
ppriv $$ # usually shows “basic” repeatedly, and after adjustment, file_dac_read

a “primitive datatype”
can be granted to a process (lab), a user/role, a zone …

full list of prvileges? no

–5 things about rbac-role
u create roles with gui
cloeset thing is an old-fashioned user — with a home dir; u can su to it with a password;
no built-in roles
“roles” commands shows what roles u can su

full list of roles? /etc/user_attr

–5 things about rbac-rights_profile
more complex than other rbac concepts
a right is a collection of (commands,authorizations,other rights…), and not a “primitive data type”
lots of built-in right profiles like ‘System Aministrator’, ‘Primary Administrator’
sometimes referred as “profiles” or “rights”

full list of right_profiles? /etc/security/exec_attr