Wednesday, February 20, 2008
Typical Software Development Project Cartoon
Posted by
blogger
at
1:07 AM
0
comments
Labels: Cartoon, Software Development
Thursday, February 7, 2008
80% of commercial apps to use open source by 2012
I had found this intresting article which claim that 80% of commercial apps to use open source by 2012, This are not good news to application software giants such as Oracle, Microsoft, Sun, IBM etc', While for every aspect of software developing you have Open Source alternative the Open Source alternative becomes more appealing for it's robutness, and for it being free.
In IDE enviroment when coming to choose between Eclipse, IntelliJ, Netbeans most choose Eclipse, In Application Server when coming to choose between WebLogic, WebSphere, JBoss and some companies use JBoss.
Tomcat, Apache, GWT all of then are open source.
So how open source projects make their profit? The answer is from support, and not only Open Source projects, many of the software applications giants make their profit from support which can reach up to 80% net incomes.
Only in companies in which the security is critical such as Banks or Goverment institutes Open Source is not being use beacuse it might containg backdoors.
Posted by
blogger
at
11:18 PM
0
comments
Labels: JBoss, Open Source, Tomcat, WebLogic, WebSphere
Design Patterns Quick Reference in two pages
I had found this amazing Design Patterns quick reference which containg All the basic design patterns in only two pages!!!
I had printed it in my office and it is very helpful when designing new components,
This great quick reference can be found at mcdonaldland blog.
Enjoy
Posted by
blogger
at
11:08 PM
0
comments
Labels: design pattern, quick reference
Saturday, February 2, 2008
2008 Acquisitions
After Microsoft bid on Yahoo for 44.6-billion-U.S.-dollar and after Oracle bought BEA and Sun bought MySql 2008 seems to be the acquistion year, the question is what would be the next big acquisitions in 2008?
Here is my bet on the next big 2008 acquisitions:
- Salesforce.com would be bought by either Oracle or SAP. Both of this software companies want to extend their On-Deman CRM services, Salesforce would put them on the front line, After Oracle bought People Soft and and Siebel it would want to extend it's CRM products even more.
- RedHat would be bought by Oracle. RedHat which posses JBoss would likely be bought by Oracle which would very interest in the Linux and to extend it's middleware products.
- Microsoft would buy Logitech to extend it's computer control devices
- IBM would continue with it's straretgy to buy only small Start-up companies
Posted by
blogger
at
11:10 PM
0
comments
Labels: 2008, Acquisitions
Tuesday, January 29, 2008
Google Interview Questions - Part 9
Q1: How you would tweak bits in C to find out if a machine’s stack grows up or down in memory?
Q2: There are 8 stones which are similar except one which is heavier than the others. To find it, you are given a pan balance. What is the minimal number of weighing needed to find out the heaviest stone ?
Q3: N threads .. n resources .. what protocol do you use to ensure no deadlocks occur?
Here are the answers:
A1: Instantiate a local variable. Call another function with a local. Look at the address of that function and then compare. If the function's local is higher, the stack grows away from address location 0; if the function's local is lower, the stack grows towards address location 0.
A2: Divide the stones into sets like (3,3,2). Use pan to weigh (3,3). If the pan is remains balanced, the heavier is in the remaining (2). use pan again to find which is heavy from (2). (Total pan use 2) If the pan does not remain balanced when weighing (3,3), pick the set of stones that outweigh other. Divide it into (1,1,1). use pan to weigh first two. It it remains balanced, the remaining stone is the heavier, otherwise the one outweighing other is heavier(total pan use 2)
A3:
- Avoiding Deadlocks with Lock Leveling, each thread would have different level, thread with high level would be able to lock thread with lower level but not contrary.
- Avoid acquiring more then one lock at a time.
- Acquire the lock always in the same order.
- Shrink synchronized blocks.
Posted by
blogger
at
1:50 PM
3
comments
Thursday, January 24, 2008
Most Popular Developers Interview Question
This is one of the most popular developers interview question I know,
I had been asked about this question so many times.
The question is about the singleton design pattern, how to ensure a single instance of singleton object.
This answer is wrong:
public MySingleton getInstance() {
if (instance==null) {
instance = new MySingleton();
}
return instance;
}
This is because if two thread would call getInstance the same time then they may both enter the if statement before instance was initialized.
Another answer for this question is to initialize instance in the creation of the class.
private static final MySingleton instance = new MySingleton();
but if the classloader is not lazy then this class would be initialized even if no one use it.
A good solution is to initalize it in a static section of the class
static {
instance = new MySingleton();
}
this code would only be called when someone create an instance of the class and two threads can't enter the same time the static section.
Another bad solution is to write
public synchronize MySingleton getInstance() {
if (instance==null) {
instance = new MySingleton();
}
return instance;
}
This is not good solution since each time someone would get instance it would synchronize the call this would decrease the performance.
So a more sophisticated good solution is:
public synchronize MySingleton getInstance() {
if (instance==null) {
synchronize {
if (instnace == null) {
instance = new MySingleton();
}
}
return instance;
}
in this case two threads can enter the first if statement in the first call but then only one of them would get into the second if since the synchronize keyword, this would create only one instance, and also this would create in lazy when the singleton is first access.
Be prepared to be asked about this question in your next interview.
Posted by
blogger
at
8:51 AM
16
comments
Spring vs. EJB 3
This article would overview the differences between Spring Framework and EJB 3
EJB 3.0
- EJB 3.0 is a specification.
- EJB is an architecture
- The EJB 3.0 framework is a standard framework defined by the Java Community Process (JCP) and supported by all major J2EE vendors. Open source and commercial implementations of pre-release EJB 3.0 specifications are already available .
Spring Framework
- Spring is an implementation.
- Spring is application framework
- The Spring framework is a popular but non-standard open source framework. It is primarily developed by and controlled by Interface21 Inc. Spring can work standalone or with existing application servers.
EJB 3.0 Advantages
- EJB 3.0 specification horroble old entity beans have been replaced with the JPA
- Deal with transactions and both succeed modularizing this functionality in a way that it doesn't clutter business logic
- Tune the transaction propagation levels via annotations
- Support state management via stateful session beans,
- Support injection of primitive types, allows injecting EJB's
- Supports AOP using interceptors
- Brings a basic implementation of component management
- Integrates with many popular persistence frameworks including JDBC, Hibernate, JDO, iBatis and JPA.
- Transaction demarcation, propagation, and isolation are all declared through its AOP.
- Support state management via prototype beans and also request, session, and global session scoping
- Support injection of any type, allows injection of any domain objects using the features of AspectJ
- Suppotrs AOP by tightly integrating with AspectJ with all of it's features
- Spring 2.0 offers a lot more power and customization, but the use of AspectJ actually makes the hard to learn
Spring Framework Disadvantages
- The idea of annotations was to stop work with XML - Deploymenet Descriptor files which were in EJB 2.1, but Spring encourage a lot the use of XML for dependency injection
- Refresh the Spring load data is impossible, if you change something in the configuration you need to restart the Application Server.
You can integrate Spring and EJB 3 technologies to take advantage of their relative strengths and weaknesses, In Spring and EJB 3 there are a lot of duplication in the compoments you can choose the best of this technologies to use in you application.
Posted by
blogger
at
4:03 AM
0
comments
Labels: Advantages, compare, Cons, Disadvanatges, EJB3, Pros, Spring, vs. EJB
Friday, January 18, 2008
Writing Cluster Application
Here is a checklist of things that need to be done to write good application which would work in Cluster enviroemnt
- When accessing the cluster from outside using HTTP or RMI verify that access to the cluster is done throught load balancer, this can be either software or hardware load balancer.
- Consider using 'Optimistic Locking' or 'Pemisitic Locking' if two or more clients may update the same row in the databse at the same time
- If you want to cache data all over the cluster and not on a single server then don't use Singleton, you would need to user Cache framework such as GigaSpaces or OSCacheor JCache etc', this solution is good mainly for read only data or data which is mostly read.
- In many application servers you can configure your MDB if it would run on a single server or on several servers.
- Avoid reading files/writing to files in the code, Since you may run on different hosts in the cluster and the files may not exists on the current host which you are running
- Use Synchronize where two threads may access the same data at the same time, This problem can also occure on non cluster system.
Please comment if you have other issues which are missing.
Posted by
blogger
at
10:10 PM
1 comments
Labels: cache, Checklist, Cluster, GigaSpaces, J2EE, JavaEE, JEE
Top Buzzwords which make you Expert
Here is a top five buzzwords which developer needs to know in order to make himself an expert
- Scalability - Means that the application can handle a growing amount of work in a graceful manner, Usage Example: "I don't think that this system is scalable, A raise in my salary might encourage me to make it scalable"
- Robustness - Means that the application can withstand stress and can continue to operate despite ourside or inside errors, Usgae Example "This application is robustness, One time I explode it with Dynamic and it continued to run"
- High Availability - Means that the application ensures a certain amount of operational continuty during a given period, Usage Example: "This application high availability stinks, we need to build a cluster of servers to make it high avilable"
- Interoperability - Means that the applications can exchange data in commonn set of exchange format. Example: "We should expose the application service with Web Services this would make our application interoperabale"
- Portability - Means that the application can run on a different operating system, Example: "In a team meating I told my boss that we should write a portable application beacuse the application needs to run also in Unix, He promote me to team leader"
Posted by
blogger
at
12:05 AM
0
comments
Labels: Buzzwords, High Availability, Interoperability, Portability, Robustness, Scalability
Thursday, January 17, 2008
Sun agrees to pay $1b for MySQL
Sun Microsystems Inc., the third-largest maker of server computers, agreed to buy software company MySQL AB for about $1 billion.
MySQL is the world's most popular open source database, over 100 million copies of its software downloaded or distributed throughout its history, It is mainly used by web sites and it is used also by Google Inc.
What is the interest of Sun to buy MySQL, well Sun unlike IBM/Oracle/Microsoft doesn't have it's own Database, Sun has its own Application Server and this would create a more complete product solution which would be supply by Sun.
The profits for Sun will come from the support for MySQL installations.
The question now when Sun would be bought and by who?
Posted by
blogger
at
9:22 AM
1 comments
Labels: Acquisition, buy, MySql, Sun
Wednesday, January 16, 2008
Oracle to Pay $8.5 Billion for BEA
Another acquestion by Oracle, this company just swallow all the other competitions.
The big question what is now what would be now with BEA WebLogic application server? Since Oracle has it's own application server 10g, would they stop to develop it? My guess is that they will continue to support old 10g customers and would offer new customer BEA WebLogic application server.
Oracle profits are just continue to grow and this cause Oralce competitiors to afraid, Now that there are now only two major J2EE Application - IBM and Oracle it would be intrest to see what would be the next acqusiton
Posted by
blogger
at
10:05 AM
0
comments
Google Interview Questions Part 8
This questions are a bit tricky, lets see if you can solve it.
First question:
1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
What is the next number?
Second question:
What number comes next in the sequence: 10, 9, 60, 90, 70, 66, ?
A) 96
B) 1000000000000000000000000000000000\
0000000000000000000000000000000000\
000000000000000000000000000000000
C) Either of the above
D) None of the above
And here are the answers:
First question answer is:
one
one one (Since the previous line has one time one number)
two ones (Since the previous line has two time one number)
one two one one
one one one two two ones
So the next line answer is 3 1 2 2 1 1
Second question answer is:
ten, nine, sixty, ninety, seventy, sixty-six,
Each number has one letter more than the previous number, ten has 3 letters, nine has 4 letters etc'
Since "sixty-six" has 8 letters the next number need to have 9 letters which is
ninety-six
You can find more questions here:
Google Interview Questions Part 1
Google Interview Questions Part 2
Google Interview Questions Part 3
Google Interview Questions Part 4
Google Interview Questions Part 5
Google Interview Questions Part 6
Google Interview Questions Part 7
Posted by
blogger
at
2:46 AM
3
comments
GWT vs. Flex
This article would compare Google GWT (Google Web Toolkit) and Adobe Flex 2 and would describe the advantages and disadvantages of each of these technologies.
This two technologies are both Rich Internet Application (RIA) frameworks.
GWT Advantages:
- Doesn't require plug in installation on the client side
- GWT doesn't require the user to know JavaScript since the code is written in Java
- GWT doesn't cost money since it is Open Source.
- Changes in the Client side are immediately shown on the browser by using refresh, no need to restart the server.
- GWT can be easily debugged in hosted mode.
- There is compatible between different web browsers.
GWT Disadvantages:
- The html and JavaScript code which GWT generates is pretty heavy and not necessary fully optimized.
- GWT doesn't come out of the box with all the possible widgets, there is a need to use extra components
Flex Advantages:
- The UI looks nicer then plain HTML/JavaScript code, It contains huge amount of animations, widgets etc'
- Compatible between different web browsers
- Flex 2 SDK and Flex Builder 2 for Education are both free
- Google can index SWF files
Flex Disadvantages:
- It requires plug in installation on the client side , however this may not be disadvantage since Adobe claims that Flash is installed on more then 99% percent of users.
- Flex Builder 2 costs some money
Posted by
blogger
at
12:23 AM
4
comments
Labels: Adobe, compare, Flex, Google, Google Web Toolkit, GWT, GWT vs. Flex
Friday, January 11, 2008
Improve SOA Performance
SOA Applications Performance are disaster.
Lets assume you want to buy a book using SOA, this means you need to access several times a remote server using web service to complete the transaction, If you work with java then for each web service request you need to parse you java objects to XML objects send the request to the remote server on the other side the XML is parsed back to java objects it do it's stuff and then return a response parse it back to XML you get the XML and parse it back to java objects.
Lets assume that each of this horrible way takes 2 seconds, if you need to send 4 requests to complete the transaction it would take 8 seconds for one small transaction!!!
To improve the performance you would first need to set a well done granularity for your web services if it is possible, For example if to buy a book you first send a request to get the book name by book if and then you send a request with the book name to check if the book exists and then you send another request to buy the book, a better way would be to send one web service request which would do all of the above this would reduce the round trips between the client and the remote server, Instead of parsing XML files 2*3=6 times you would parse only 2 times.
A second way to improve the performance is to cache locally all the read only data which exists in the remote server, so instead of accessing the server using web service you would just read the data from the cache, You can also cache not read only data if you don't necessary need the last-to-update date.
Technical ways to improve the performance is to choose a good performance web service package, some packages take a lot of CPU/Memory to parse the XML to objects and vice-verse.
I recommend this SOA book to learn more:
Posted by
blogger
at
11:13 PM
1 comments
Labels: Improve, Improvement, Performance, SOA, Tips
Tuesday, January 8, 2008
Flex vs. JSF
This article would compare Flex and JSF technologies and would describe the advantages and disadvantages of each technology.
JSF Advantages:
- Doesn't require plug in installation on the client side
- JSF has a standard specification and it has several implementation
- JSF has Open Source implementations which doesn't cost money.
- Changes in the JSP files are immediately shown on the browser, no need to restart the server.
JSF Disadvantages:
- Very complicate to develop because the basic implementation is pretty basic and for complicated UI screens need to have additional component libraries
- Doesn't compatible between different web browsers
Flex Advantages:
- The UI looks much nicer then JSF UI
- Flex looks like more simple to develop rather then JSF
- Compatible between different web browsers
- Flex 2 SDK and Flex Builder 2 for Education are both free
Flex Disadvantages:
- It doesn't has standard specification
- Adobe is the only provider of Flex
- It requires plug in installation on the client side , however this may not be disadvantage since Adobe claims that Flash is installed on more then 99% percent of users.
- If you build a web site which users would need to search in some search engine the search engine would not be able to understand the content of the flash files (search engines can only understand standard html files/pdf files etc')
- Flex based pages takes a lot of time to get loading compare to JSF pages
- Flex Builder 2 costs some money
Both JSF and Flex integrate very well with java.
In summary, if you build an simple enterprise application which requires nice UI I would recommend using Flex, if you build an complicated application which requires good performance or application which is open to all the Internet users I would recommend using JSF.
Posted by
blogger
at
8:12 AM
7
comments
Labels: Advantages, compare, Disadvanatges, Flex, JSF
Sunday, January 6, 2008
GWT Proxy
Here is a nice way to write GWT Proxy to call the server services using the proxy design pattern:
The advantages of this proxy are:
- The client call the service as it's a local call
- The proxy hides the difference between calling the services in hosted and development modes.
- It improves performance since the end point is set only once
First write this Client util class:
public class ClientUtil {
private static final String PRODUCTION_URL = "http://www.koko.com";
/**
* Check if the code run in production or development mode
* @return true if we run in production mode (i.e. Ruler.html is called)
*/
public static boolean isProduction() {
return GWT.isScript();
}
/**
* Set endpoint for service which want to access the server
* @param service the service class
* @param name the name of the service
*/
public static void setEndpointForService(Object service, String name) {
ServiceDefTarget endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = getRelativeURL() + name;
endpoint.setServiceEntryPoint(moduleRelativeURL);
}
public static String getRelativeURL() {
String moduleRelativeURL = null;
if (!isProduction) {
moduleRelativeURL = GWT.getModuleBaseURL();
} else {
moduleRelativeURL = PRODUCTION_URL;
}
return moduleRelativeURL;
}
}
Then write your proxy class, for example:
package com.mycompany.client.util;
import com.google.gwt.core.client.GWT;
public class MyProxy {
private static MyServiceAsync myService = (MyServiceAsync) GWT.create(MyService.class);
static {
// serviceName is the name which define in app.gwt.xml file
ClientUtil.setEndpointForService(myService, "serviceName");
}
public static void foo() {
MyCallback myCallback = new MyCallback();
myService.getServerLog(myCallback);
}
}
finally to call the server use:
MyProxy.foo();
You can read more at:
Posted by
blogger
at
9:59 PM
0
comments
Labels: GWT, Implementation, Performance, Proxy
GWT Development or Production Mode
Here is a nice trick to know if your GWT application runs on hosted mode (development mode) or does it runs in production mode on a real web site.
Why do you need this? Because your access to the server side is different between development and production modes, and because you might your application behave differently between this two modes.
So to do this you would need to have two main html files one for development mode and another one for production mode, the two html are the same expect in the production mode you would put this following line:
‹iframe id="production" style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; WIDTH: 0px; BORDER-BOTTOM: 0px; HEIGHT: 0px"›‹/iframe›
and you can also put your advertisements like Google AdSense and Google analytics and other production stuff.
after you put this write this code in your main module class:
public void onModuleLoad() {
Object isProduction = RootPanel.get("production");
if (isProduction!=null) {
ClientUtil.setProduction(true);
}
Also create this ClientUtil class:
public class ClientUtil {
private static boolean isProduction = false;
public static boolean isProduction() { return isProduction; }
public static void setProduction(boolean isProduction) {
ClientUtil.isProduction = isProduction;
}
}
Now in every place in the code user ClientUtil.isProduction() to know if you are in production or not.
Posted by
blogger
at
12:10 AM
5
comments
Labels: Development, GWT, Mode, Production
Tuesday, January 1, 2008
Java becoming old?
Some "experts" claiming that Java becoming old and that it would reach it's end in a few years,
Some of these "experts" claim that java would end as Cobol, and new technologies would be adopted such as "Ruby On Rails", PHP and Ajax.
I completely disagree with this statements, First of Cobol is still one of the most common software programming languages. Beside that other new technologies such as Ruby still doesn't mature - we've tried several projects with it and have reverted to Java.
PHP is cool, but doesn't scale as well as Java for large user base applications.
AJAX -is like Javascript and CSS; It intended to be used with JSP/ASP/HTML etc.
Java still is the best choice - by far - for development. It runs on virtually any platform and doesn't lock you in to one OS vendor or flavor. It works, and it's fast. It's a great tool for back-end and web development. Yes, it's not the newest kid on the block, and frankly that doesn't matter much - It has solid performance and results pretty well in production
Posted by
blogger
at
1:41 AM
0
comments
Labels: Ajax, Cobol, Java, PHP, Ruby on Rails
Saturday, December 29, 2007
Google Interview Question - Part 7
Here is another question:
Write a function f(a, b) which takes two character string arguments and returns a string containing only the characters found in both strings in the order of a. Write a version which is order N-squared and one which is order N.
And here is the answer:
A:
private static String match(String a, String b)
{
String result = "";
Set lettersSet = new HashSet(26);
for (int i=0; i lettersSet.add(new Character(b.charAt(i))); } for (int i=0; i if (lettersSet.contains(new Character(a.charAt(i)))) { result=result+a.charAt(i); } } return result; }
Thursday, December 27, 2007
Hibernate .vs. Pure JDBC
There is a wrong assumption that Hibernate is slower then JDBC, this is not true.
For the tests that I have done I had found that Hibernate performance are not less then Pure JDBC.
I had compared the performance between Hibernate and Pure JDBC for writing 10,000 rows to the DB table, The results are really surprising.
The test run on a single thread which write in a loop the rows in bulk update, the JDBC used batch update processing with prepared statement, the Hibernate run on a single session which flush the inserts to the DB every 100 rows (Bulk Updates).
I had worked with Hibernate 3.0 on a regular Pentium Pentium 4 2.66GHz with 2GB RAM, The DB was remote Oracle 9 DB.
Well are are the surprising, Hibernate and Pure JDBC results are completely the same !!!
Hibernate doesn't have a huge overhead as you expect it to have.
For the results I manage to write 10,000 rows to the DB in 1.5 Seconds !!!
Here are some tips for improve your Hibernate performance are:
- Try to reduce the number of open and close of hibernate sessions
- Using Hibernate bulk updates were possible
- When using Hibernate bulk updates try to separate the SQL Insert/Update/Delete statements to groups, the DB would process this groups faster (For example 20 SQL inserts then 40 SQL updates and then 25 SQL delete statements)
Posted by
blogger
at
7:04 AM
15
comments
Labels: Hibernate, Hibernate vs JDBC, Jdbc, Pure JDBC, Results, Surprising
Wednesday, December 26, 2007
SAP licenses NetWeaver to developers
I found this nice article which says that SAP netweaver can be now used by individuals:
http://www.regdeveloper.co.uk/2007/10/03/sap_netweaver_developer_license/
As I had experience working the the SAP netweaver J2EE Engine - AS (Application Server), I can tell you about my impressions.
The disadvantages are:
- It take a lot of time to startup the server and to deploy applications (depend on the application size)
- There are a lot of missing infrastructures which exists in other application servers (such as inline scheduler, cluster singleton, hot deployment) and many open source frameworks wouldn't work properly with the server.
- All the infrastructures in the server a propriety of SAP (Logging, Security etc')
- Except SDN there isn't huge community which can help with the development, Other J2EE Engines like JBoss has a lot of forums with questions and answers inside them.
The advantages are:
- There is a good administrator GUI to manage the server.
- It is possible to deploy several applications with references between them
- There is a good JCA, JCO, Web Services infrastructure to connect to the ABAP world.
Again this list are from my personal experience.
Posted by
blogger
at
1:37 AM
0
comments
Labels: ABAP, Advantages, Developers, Disadvanatges, Netweaver, SAP
Sunday, December 23, 2007
Build Web Application
The big question is the technology is ready to build web application, there are many web applications out there, word processing, spreadsheet, CRM, mail reading and more...
Until now the only application that really succeed running in web is mail reading like http://www.gmail.com/ and CRM application like http://www.salesforce.com/ why is that?
GMail succeed because you want to read you mail from anywhere in world, It has a very good spam filter which and it run pretty fast on the web, the disadvantages which it has are:
- It is limited in storage space
- It can't run offline and the data is not private.
- Download/upload huge file can take a lot of time
So what the the characteristics which are require by a good web application:
- It should run offline, so if the connection to the Internet is closed it would be possible to keep working on the application, This can be done by using Google Gear technology for example.
- It should be able to synchronise the files on the local machine with the server if the user wants to share his own local private data with other users.
- The Application would be able to know that there is a new software release on the server and upgrade to the new release offline.
- The initialize of the web application would take long time only on the first time accessing the application, since then it should cache on the browser cache directory and run locally.
- The user would be able to save his own private work data locally on the machine, the web application would know to synchronize it with the server in asynchronise way.
Posted by
blogger
at
10:04 AM
0
comments
Labels: On Demand, SAAS, Web Application
Saturday, December 22, 2007
XA Two Phase Transactions doesn't work
When you use XA or in it's second name Two Phase Commit Transaction and the transaction doesn't work it can be cause by one of the following reasons:
- You didn't declare transaction manager in your application server or in your spring XML configuration file
- You declared transaction manager but no annotation was defined for the EJB or the annotation was defined NOT_SUPPORTED
- There is annotation but if you call from some method in the EJB to another method in the same EJB the second method can't open transaction since it is a local call which doesn't execute through the j2ee engine interpreter and therefore not transaction is opened. A Possible solution for that is to use UserTransaction and open the transaction pragmatically or to move the second method to another EJB.
Posted by
blogger
at
1:48 AM
0
comments
Labels: Solution, Two Phsase Commit doesn't work, XA
Google Interview Question - Part 6
Continue with the question in the previous post:
http://j2ee-now.blogspot.com/2007/12/google-interview-questions-part-5.html
Here is the answer to the question,
If two threads would run in parallel and call this method with values 10 and 7,
The first thread would create the array with size 10 and then thread 2 would re-initialize the same static array with size 7, then the fist thread would run on the array from 0 to 9 and would put values inside however the array size is now 7 so on list[7] it would throw the exception.
Wednesday, December 19, 2007
Runtime Exception or Regular Exception
This is the question that asked often, when should I throw RuntimeException and where should I throw regular Exception, this is the answer:
- If you exception which is thrown is pure technical exception from which the client can't recover from then throw RunTime Exception in case you run in J2EE server with Transaction Manager set then it would also rollback the transaction. Even that this exception doesn't have to be declared as part of the function exception signature it is advice to declare it so the client would be aware for this exception.
- If your exception is pure business applicative exception then this exception should be regular not RunTime exception so this exception would be displayed for the user in the end and he would be able to change something to fix it, when throwing this exception in J2EE server with Transaction Manager the transaction doesn't rollback.
Posted by
blogger
at
9:19 AM
0
comments
Labels: J2EE, Regular Exception, RunTimeException, Throw, When

