Now we're going through a simple setup of an EJB application on MT environment to demonstrate the usage of some of these features.
The EJB application archive is named sampleEJB.jar, it includes a stateful session bean which interacts with database by JPA API. We want the application to be deployed to 2 separate partitions, each of which points to a database instance of its own, so they can work independently.
The first step is to create 2 virtual targets for the 2 partitions respectively, which use different URI prefixes /partition1 and /partition2 respectively as showed below.
Now we create a Resource Group Template named myRGT. Resource Group Template is a new concept introduced by WLS 12.2.1, to which you can deploy your applications and different resources you need. This is very helpful when your application setup is complicated, because you don't want to repeat the same thing for multiple times on different partitions.
Now we can deploy the application and define the data source as below. Please pay attention that the application and the data source are all defined in myRGT scope.
Now everything is ready, it's time to create partitions. As the following image shows, we can apply the Resource Group Template just defined when creating partitions, it will deploy everything in the template automatically.
Now with the partitions created and started, you can lookup and access the EJB with the following code. We're using the URL for partition1 here, you can also change the URL to access another partition.
Hashtable<String, String> props = new Hashtable<String, String>();
Context ctx = new InitialContext(props);
BeanIntf bean = (BeanIntf)ctx.lookup("MyEJB");
boolean result = bean.doSomething();
If you're feeling something is wrong, you're right. We defined the data source myDS in myRGT, then applied myRGT to both the partitions, now the 2 partitions are sharing the same data source. Normally we don't want this to happen, we need the 2 partitions to work independently without disturbing each other. How can we do that?
If you want to make partition2 switch to another data source, you can do that in the Resource Overrides tab of partition2 settings page. You can change the database URL here so another database instance will be used by partition2.
As mentioned above, for EJB applications it's supported to dynamically change the transaction timeout value for a particular partition. This can also be accomplished in partition settings page. In the following example, we set the timeout to 15 seconds. This will take affect immediately without asking to reboot.
There're also some other things you can do in the partition settings page, such as defining a work manager or monitoring the resource usage
for a particular partition. Spend some time you will find more very useful tools around here.