Tuesday, July 31, 2007

Dead locks


Deadly embrace
I think any OS class student remembers the "Chinese philosophers" problem. Anyway this problem represent only one format of deadlocks a.k.a deadly embrace.
In contrary to Java, database servers detect and resolve deadly embraces by using a graph that nodes transaction and edges represent the A needs a lock that B is holding, if there is a circle in this graph, then a deadly embrace has happened.

**: my first thought on this problem was that: why not they try to eat with only one chopstick, you agree that it's better than starving, we 'll get to this solution later as a general solution to avoid deadlock, just read on ;)

Lock-ordering Deadlocks:

Consider this priece of code :

// Waning: deadlock-prone!

Public class LeftRightDeadlock {

Private final Object left = new Object();

Private final Object right= new Object();

Public void leftRight() {

Synchronized (left) {

Synchronized (right) {

Dosth();

}

}

}

Public void rightLeft() {

Synchronized (right) {

Synchronized(left) {

Dosth();

}

}

}


As you can see, these two methods can cause deadlock, because:


in general :

A program will be free of lock-ordering deadlocks if all threads acquire the locks they need in a fixed global order.

To add to this I want to mention that problems are not always as clear as our sample, just consider the case that there is a method that lock orders is based on its first parameter and then second parameter, in this case if the passed attribute changes in two seperate calls, the same non-global order will raise, using a rule for acquiring locks that make it independent of order of varaibles is the right solution(ex. using a general comparison method [a global method] to indicate lock orders).

**: Another solution can be wrapping the sequence of locks with a 3rd lock as a tie breaker, but this solution basically cause a concurrency bottleneck and again it is using only one lock instead of having two seperate locks.

For more reading, look at this javaWorld article.

Multiple lock acquisition is not always happening in the same method.Invoking an alien method from a method that has held a lock is asking for liveness trouble. The alien method might acquire other locks (risking deadlock) or block for an unexpectedly long time, stalling other threads that need the lock you hold.

Alien method :Methods that their behavior is not fully specified by this class (non private, non-final methods of the same class [ they are overrideable] and methods of other classes






Saturday, July 28, 2007

Little people - Novels

It has been a while that I hate people in power, this feeling is combined with a consideration and admiration for following little people stories, little people who panic, get mad and can't do much about it other than panic again. I *care* about them.

Words-of the day (2)

bear a resemblance - bear a signature = have...

Friday, July 27, 2007

Smart

This was smart specially [Ba labkhand khande shavad]

Daddy (1)

You know what I 've missed you, even though you 'll not gonna read this but I feel I am talking to you!
I discovered people do not like failure, mad people and sadness, they don't like disharmony, but it is fine by me, I like it, maybe it shows sth like I am artist or I can find sth in the chaos. It is possible you know! I was thinking of some entertainment innovation, maybe I did it, even though P.S. is giving me hell but actually it is not him, it is me facing my fear.

Thursday, July 26, 2007

Help yourself

Did not see this coming!

XSLT and Sql : an Anology (2)

1- Declerative query syntax for selecting the data that needs to be processed.

Sql: Select XSLT: XPath expression (eventhough xpath can be used independent of xslt)
(the relation of XSLT and XPath will be discussed later)

  • Both SQL and XSLT augment the basic query facilities with useful additions for performing basic arithmetic, string manipulation and comparison operations.
  • Both languages supplement the declarative query syntax with semi-procedural facilities for describing the sequence of processing to be carried out, and they also provide hooks to escape into conventional programming languages where the algorithms start to get too complex.
  • Both Languages has closure property, which means that the output has the same data structure as the input. For SQL, this structure is tables, for xslt it is trees. the closure property is extremely valuable because it means operations performed using the language can be combined end-to-end to define bigger more complex operations.
Interestingly in real world sql and xslt should coexist because data are stored in databases and transfered via xml. These two languages don't fit together as comfortably as one would like, because the data models are so different. But XSLT transformations can play an important role in bridging the divide.[ RDBMS vendors are seeking this.]

XSLT and SQL: an Analogy

Relational database power is not because of their strutures (tables and their relations) but it is in the language that process the data, SQL. In the same way, XML just defines a data structure.But having a high-level language to manipulate data make it powerfull, that languauge is XSLT.

To_be_continued: Defining an anology between SQL language and type of manipulation/query that it provides in compare to xslt abilities.

Label

I hate it when someone tells me that I will like this or sth will fit my personality ,...you know why? Because I do not like to be defined or known with lables, I think I have already proofed in Amene's history that there is no linear thing in it, now you tell me that it fits my personality :|
Saaaaaaaaaad.

Shaky

When your job starts not to be as stable as before, you start questioning and rethinking all the things that you were counting on before, like this cubicle, space, street that you always walk down to get to the little park at Alameda; none of them will be there for you if you quit tomorrow. Today I stayed home to figure out what is really mine.
Big question is about ownership and dependency.

P.S: May be being a contractor makes things more real.

Channel

If you are not scared of anything and you don't leave any channel open, no one can ever reach you, or can they?

Fence

I really like these wooden brown fences I dunno is it because I can stare at them and feel that the whole world is pinned stably in place or is it because by being there they are kinda saying that on this side, we rule. ;)

Wednesday, July 25, 2007

XSLT (XML transformation Language) 101

XML Bean : is the Apache XML project.

In June30 2005 XmlBean ver2.0 was released that has:

  • Improved XQuery/XPath integration - Both XQuery and XPath on XMLBeans are now fully integrated. XPath and XQuery expressions can return other XMLObjects, or they can be executed using an XmlCursor instance, in which case you manipulate the results using a cursor.
  • DOM Level II Support - DOM Level II support is now implemented natively so that you can handle the underlying XML in the DOM style. You can switch between
  • DOM,
  • XmlCursor,
  • and XmlObject (either untyped or typed).
  • This improves performance and reduces the memory footprint over Version 1.
  • Extensions - You can now add custom functionality to generated XMLBeans. You can pass to the Schema Compiler
  • 1) an interface that defines the set of methods to implement and
  • 2) a static handler that implements this functionality. The generated classes will implement the interface and, for each method, call out to the static handler.
The xbean_xpath.jar is used in conjunction with saxon-8.2 to execute xpath and xquery expressions.

Tuesday, July 24, 2007

jdk1.5 major themes

  • Reliability, Availability, Serviceability: to support critical applications developed by java
  • Monitoring and Manageability: to support critical applications developed by java
  • Scalability and Performance : for server and client side
  • XML and Client Web ServicesEase of Developmen: ease of client developments

Jdk 1.5 - JSRs

A good compromise to move on could be getting an overview of Tiger (jdk 1.5) JSRs:

JSR-003 JavaTM Management Extensions (JMXTM) Specification
JSR-013 Decimal Arithmetic Enhancement
JSR-014 Add Generic Types to the JavaTM Programming Language
JSR-028 JavaTM SASL Specfication
JSR-114 JDBC Rowset Implementations
JSR-133 JavaTM Memory Model and Thread Specification Revision
JSR-163 JavaTM Platform Profiling Architecture
JSR-166 Concurrency Utilities
JSR-174 Monitoring and Management Specification for the JavaTM Virtual Machine
JSR-175 A Metadata Facility for the JavaTM Programming Language
JSR-199 JavaTM Compiler API
JSR-200 Network Transfer Format for JavaTM Archives
JSR-201 Extending the JavaTM Programming Language with Enumerations, Autoboxing, Enhanced for loops and Static Import
JSR-204 Unicode Supplementary Character Support
JSR-206 JavaTM API for XML Processing (JAXP) 1.3

Jdk 1.5 Metadata / Annotation

As for noble metadata
I'll have to sing its praises later
Its uses are so numerous
To give their due, I'd miss the bus






http://www.jcp.org/en/jsr/detail?id=175

Words of the day

feat : A notable achievement

boilerplate : Standard formulations uniformly found in certain types of legal documents or news stories

ex. bolierplate code

Monday, July 23, 2007

J2SE 5 (Tiger)

I was reading about jdk1.5 new features, that I saw this:

Tiger, Tiger burning bright
Like a geek who works all night
What new-fangled bit or byte
Could ease the hacker's weary plight?

< -- Using Generics with Java Collections to avoid cast and error encapsulation-- >

To the most despised collections' cast
We'll bid a fond farewell at last
With generics' burning spear
The need for cast will disappear

< -- adding some equivalent of: foreach (element in collection) -->
While Iterators have their uses
They sometimes strangle us like nooses
With enhanced-for's deadly ray
Iterator's kept at bay

When from the collections ints are drawn
< -- Ease the interoperability between primitive types and references -->
Wrapper classes make us mourn
When Tiger comes, we'll shed no tears
We'll autobox them in the ears

< -- Enum Keyword, EnumSet and EnumMap -- >
The int-enum will soon be gone
Like a foe we've known too long.
With type safe-enum's mighty power
Our foe will bother us no more

< -- import static java.lang.System.* or import an interface to use its static memebers
-- >
And from the constant interface
We shall inherit no disgrace
With static import at our side
Our joy will be unqualified

< -- Annotation allows parsing of Java files and generating boilerplate artifacts such as XML descriptors or source code -- >
As for noble metadata
I'll have to sing its praises later
Its uses are so numerous
To give their due, I'd miss the bus

< -- variable arguments: ... ; Formatted output: printf ; Enhanced input: java.util.Scanner,java.util.Formatter ; Synchronization:java.util.concurrent TO BE CONTINUED -- >
O joyless nights, o joyless days
Our programs cluttered with arrays
With varargs here, we needn't whine;
We'll simply put the args inline

< -- Overall tiger is acheving more compile-time typesafe checking -- >

Tiger, Tiger burning brightLike a geek
who works all night
What new-fangled bit or byte
Could ease the hacker's weary plight?

< -- what a geek -->