perl accept()

I think a common Perl socket idiom (used repeated in my scripts) is


while ( accept(Client,Server) ) {
# use Server and Client file handles
close Client;
}
close Server;

I think the while loop would run only once (P 442 [[ programming perl ]]). The first time it runs, accept() blocks until a client connects. After the connect, the loop runs for n seconds, the duration of the connection. At end of the connection, this script closes Client, exits the loop (?), and closes Server stream.

How does the server continue to service other clients? I think fork and exec is the standard solution, spawning a new process. In contrast, Java spawns a new thread — perhaps more efficient.

Remember a single-thread NIO server can handle thousands of sockets, one for each concurrent client. Even a traditional IO server can spawn hundreds of threads.

Hundreds of “processes” sounds like too heavy for an ordinary OS. Apache httpd in our servers typicall spawn dozens of child processes.

Advertisements

finally execution is "guaranteed"@@ UNLESS

[24 May] guaranteed by JVM.

q: unless system powers off before it can?
A: agree. since the guarantee is given by jvm.

a7: finally still runs. Perhaps finally can do a return and /disarm/ the bomb?

q: unless the fatal error leads to an immediate jvm crash?
A: I don’t think so. If JVM can manage the fatal error, it can run finally{}.

q: what if there’s an endless loop in the try or catch?
A: then finally{} is expected to be delayed. JVM will honor the class owner’s expectations.

a690: right before the search for a /matching catch/ in the stack? see other blog posts on try/catch/finally execution order

q7: when does my finally run if my catch says exit()

q690: when does my finally run in the presence of my catches and also catches up on the call stack?

cross rate derivation illustrated

There’s confusion over the term “cross”. I believe it means the pair is not “native” to the broker/dealer you are using, so they have to synthesize 2 “native” trades. If your broker/dealer offers only USD/XXX , then a lot of non-USD currency pairs will be crosses.

If you are a big dealer bank using EBS and Reuters, then you can combine those 2 brokers’ offerings together and present a consolidated list of “native” pairs. Anything not in the list is considered a cross currency pair. Note EBS/Reuters “native” spreads are very tight. This is a defining feature of “native” pairs.

Since a cross is always synthesized using 2 pairs, transaction cost (and bid/ask spread) is higher.
——————-
In the context of “cross rate”, this term means “an exchange rate between 2 non-USD currencies”. That’s a USD cross. There are also Euro crosses — any non-Eur currency pair whose rate is computed from 2 Eur rates.

If USD/AAA has a bid/offer and USD/BBB has a bid/offer, and CCC/USD has a bid/offer. When computing the cross rates between A B and C, just remember to always take the worse prices, which are the safest prices for the market-maker.
– Offer of the cross pair is worse joining worse
– Bid of the cross pair is worse joining worse too

One principal, but many scenarios. Here’s one scenario.Given
1) USD/CHF = 0.9648/52
2) USD/JPY = 82.64/69
CHF/JPY offer must be computed as USDJPY / USDCHF, but which number by which number? Worst offer quote is the highest, so 82.69 / 0.9648 = 85.71.

Here’s the math explained in English. As a market maker who is publishing the 4 quotes of 1) and 2), at what price am i willing to convert my CHF into JPY? Well, I would convert to USD then JPY, using the safest/greediest conversion rates among my outgoing quotes. I would safely convert from CHF to USD at 0.9648, then safely convert from USD to JPY at 82.69.

2min intro to NULL (sql)

http://www.oracle.com/technology/oramag/oracle/05-jul/o45sql.html is a more complete list of jolts. But for now …

#1 jolt: “the NOT-trap” for any cond3 such as “amount > 10” or “id=order.customer_id” … ,
if
select … where cond3 –> 30% of the rows,
then
select … where NOT cond3 –> ?


#2 jolt: “ignore”

where col3 = …
where col3 > …
where col3 LIKE …
where col3 IN …

These filters will ignore NULL entries. Yes, ignore their existence. Reason? null means “unknown” so such an entry is perhaps IN and perhaps not IN.

context-scope = application-scope

I have seen authors using the twin terms “context-scope” and “application-scope” interchangeably.

This is the first thing to bear in mind. After that, recognize that

* context-scope is related to ServletContext, a name used repeatedly in some files
* application-scope is related to web-app, a name used in some files too.

Lastly, remember that we are talking about ATTRIBUTES when we mention these scopes ie

context-scope attributes = application-scope attributes

P309 [[ head first servlet ]]

identical hashCode in HashSet

A HashSet containing 2 twin objects with identical hashCode()?

I think they will co-exist in the HashSet. hashCode() never promises “unique” hashcode, but HashSet promises that 2 “different” objects would be accepted as 2.

Now “different” and “same” are defined by … equals() method , which should be overriden in the key classes used as HashSet keys.

php packages4people build`a simple site

Mambo, moodle, phpnuke, drupal are some of the well-known php “content management” packages. I once used mambo and moodle. Exellent quality and usability.

These open-source packages can help a lay person put together a website quickly. Compared to a from-scratch approach, a package offers, among other things,
* nicer web pages
* perhaps faster development, if the package supports your requirement
* fewer bugs, better tested

There are drawbacks.

* Your custom database logic may be harder to implement.

* I feel you would have a hard time understanding the source code — dozens of source files, containing thousands and thousands of lines — before you can “hack” the code.
* you may realize you only need 1% of the source code to implement your requirement. It would have been far more manageable if you could throw away the other 99%. Not easy.

If you have time to search, see if you can find some bare-bones php “content management” mini-packages. If you find one, let me know.

onion&&remote-control — static binding

Runtime binding is covered in a few posts with onion and remote-control. Now let’s apply our analogies to static method binding. P 45 [[ java precisely ]] has a good example 59.

C2 c2 = new C2(); // C2 extends C1 and hides a static method C1.m1() with C2.m1()
C1 c1 = c2;

Now c1 and c2 are 2 remote controls programmed for a single onion, the “biggest onion” [1]. However,
* variable c1 is a remote control of type C1 and supports C1.java’s static m1() only
* variable c2 supports C2.java’s static m1() only.

Now the question:
Q: how are the various calls to m1() resolved.
A: C1.m1() and C2.m1() are obvious.
A: c1.m1() binds to C1.java static m1(). The onion, which happens to be a C2 onion, doesn’t affect the resolution.
A: c2.m1() binds to C2.m1()

[1] Therefore instance methods c1.m1(int) and c2.m1(int) {c1 c2 both lower-case} are both bound to C2.java m1(int). Runtime binding of instance method m1(int).

java static field – root object@@

Get Inside the static initializer In FTTP loader. Suppose we define a var like

XMLElement xml;

Q: will it get garbage collected at end of the initializer?
%% A: I think so. Read P8 [[ java precisely ]] top to bottom. When such a variable goes out of scope -> unreachable. I think this applies to any variable declared in a block or in a for(int i=0….)

Q: But static ? root objects?
A: I think a static /field/ is a root object “reachable” from any thread [1]. Our local var is not a static field.

[1] pubic or otherwise, I believe it’s a root object. See blog on GC root objects

citi IV @longisland-city 2007

Q: ok u use subversion. what do u do if u have 2 versions of the code for 2 clients and then u need to apply an important change to the shared codebase.

Q: describe the process of starting a new project. (they expected SIT, documentation)

q: describe the standards and processes in a large company that you worked in. (I think they expect some kind of escalation, approval …)
Q: vector vs arraylist? what they have in common?
Q: struts tags?
Q: benefits of hibernate?
Q: is hashmap synchronized?
A: u can do collection.synchronizedmap(the hashmap intance)
Q: in an unsynchronized method, do u need to synchronize a local var?
Q: write the code where an Action class get access to a bean in a struts environment

if constructor throws ..

myInstance = new MyClass() ;

Will myInstance become null or …?

I feel the assignment should leave myInstance unchanged. The constructor (which strictly are not “methods”) , like methods, won’t return anything to the caller. The constructor, the caller, and upstream callers may each be aborted.

See blog on exceptions in call-stack

 


For c++, a throwing ctor is common. If on the heap, the compiler will release the memory.

thread ] NextGen

* Our system runs on SPARC and I know the new SPARC processors feature a large number of kernel threads — 32 kernel threads in T2000.
* NextGen is massively multi-threaded to deal with perhaps hundreds of concurrent sessions, each lasting 15 minutes to several hours.

* open call in constructor
* singleton in a multi-threaded environment
* promote local variables
* promote constants and immutables
* immutables as much as possible. Some things in a circuit model are updatable. Most are not, but if you don’t enforce immutability in your classes, then other objects could accidentally attempt to modify my objects’ states, posing a threading hazard.
* log4j logger ? It’s not just thread-safe, it uses synchronized methods everywhere. That means that for heavy logging log4j will induce performance bottleneck and possible deadlocks

— static fields
* EVERY static field is accessible by (true) concurrent threads.
* static fields are needed to model many characteristics of a given telecom equipment, such as …
* In my modules, static varables are mostly constants

— instance variables
* In terms of threading concerns in my modules, instance variables are trickier than static fields
* my classes use more instance variables than static fields, typically 10 – 50 in each object.
* EVERY instance var is, by default, open to hazardous concurrent access
* System was designed to assign 1 thread to each “trouble ticket”, thus minimizing concurrent access to instance variables of circuit elements. Similar to servlet.
* instance vars of parser object? Parser is supposed to be a singleton, so those instance fields are similar to static fields.