Difference between String, StringBuilder and StringBuffer in Java commonly asked question in interview

String is one of the most commonly used class in java used by a developer. String can be used for multiple purposes for run time values, string manipulations , etc. But many developers ignore the fact that Strings are IMMUTABLE. That is whenever a value for string is modified a new internal memory is allocated for storing the string value and thus the previous value remains unchanged.

Being IMMUTABLE and final in nature it makes its hash code value to be cached and thus used in hash map for faster hash map key reference and also becomes useful in multiple thread execution being a thread safe value.

Accessive use of string operations in your code like upper case, lower case, concatenation, sub string leads to performance issue. So to manipulate the strings without creating STRING GARBAGE can be done with either StringBuffer or with StringBuilder.

Now, next question comes here whether we want the data to be thread safe or not ?

StringBuffer and StringBuilder both are mutuable and thus operation done on the StringBuffer or StringBuilder object does not create any new object. The main difference is that StringBuffer has all its public methods are SYNCHRONIZED which makes it thread safe but also makes it slow in execution. On the Other hand, StringBuilder is not synchronized and has same methods as StringBuffer has.

So we can summarize the following
1) String is immutable while StringBuffer and StringBuilder is mutable object.
2) StringBuffer is synchronized while StringBuilder is not which makes StringBuilder faster than StringBuffer.
3) Concatenation operator “+” used in String is internally implemented using either StringBuffer or StringBuilder.

Developer should use String if require immutable objects
Developer should use of StringBuffer if require object to be mutable and thread safe
Developer should use StringBuilder if require mutable and no thread safe.


Optimize and tuning for weblogic data source connection timeout

Data source connectivity is quite important for an application and make sure that all possible features are set and available before executing the application scenarios:

Weblogic Connection Pool Settings

  1. Maximum Capacity: This is calculated based on the number of sessions allocated in database / number of weblogic servers. If total sessions is 200 and 4 weblogic servers , then maximum capacity will be 200 /5 = 40
  2. Initial Capacity:  This includes the number of sessions made available at the time when server starts. It is also said that keep the initial capacity to maximum capacity so that all connections are available but the server will not be able to use all the available connections till it reaches the peak load.
  3. Capacity Increment: Ideal value for this should be less than 10. I have kept 5 only.
  4. Shrinking Frequency: This indicates the number of seconds to wait before shrinking a connection pool that has incrementally increased to meet demand.
  5. Statement cache type:  The most commonly used algorithm is LRU (default).  LRU stands for Least Recently Used. Weblogic Server caches the executed statements to avoid database call for the same statement required to be executed again by some other thread.  Once the cache is full then weblogic server determines which existing statement in the cache was the least recently used and replaces that statement in the cache with the new statement.
  6. Seconds to Trust an Idle Pool Connection: This indicates the number of seconds within a connection use that weblogic server trusts that the connection is still viable and will skip the connection test, either before delivering it to an application or during the periodic connection testing process. Default value is 10.
  7. Connection Timeout: While creating the data source, add the below property in the connection pool tab for adding the increased value for the connection timeout. Oracle.net.CONNECT_TIMEOUT=10000000
  8. Statement cache size:  The number of prepared and callable statements stored in the cache.  The statement cache depends upon  below factors:

–          Number of servers which data source deployed

–          Maximum connection for data source

–          Maximum cursor open allowed on database side

Weblogic statement caches related to database cursor and cache contains too many statements and reaches maximum limit of open cursors can impact the server performance. Try to reduce Statement Cache Size setting value or   increase maximum open cursors allowed for a connection


Difference between Weblogic development mode and production mode

The blog provides the difference between the Weblogic Server Development Mode and Production Mode features

WebLogic Server Development Mode

  • WebLogic Server domains uses the Sun Java Development Kit (JDK) when running the Development Mode .
  • The WebLogic Server Development Mode enables auto-deployment of applications. The Weblogic Admin Server creates a boot.properties file automatically at the server start up.
  • The WebLogic Server Development Mode also provides the demo certificates for Secure Sockets Layer (SSL) and allows developers a quick and easy available environment up and running to perform deployment, configuration, or security issues
  • The DebugFlag is used to enable the WebLogic Workshop Debugger.
  • Change center is disabled and doesn’t require the Lock and Edit session.
  • JRE Mode is -client, The Client VM provides high performance for applications and applets and reduces application start-up time and memory footprint
  • page_check_seconds in weblogic.xml file is 0. When a jsp is edited and deployed not using the autodeploy folder, then jsp pages are recompiled and served
  • Fast swap is enabled to ensure Java classes are redefined in-place without reloading the ClassLoader to reduce the overall compilation time for developers
  • In The WebLogic Server Development Mode, the configuration for security is relaxed

Weblogic Server Production Mode

  • The WebLogic Server Production Mode does not support auto-deployment mode to reduce the overhead of continuous polling of directory updates. The deployments in the WebLogic Server are supported through Administration Console, weblogic.Deployer tool or the WebLogic Scripting Tool (WLST)
  • The Weblogic Server provides additional features when it is to be used for the production environment. The Weblogic Server production mode provides additional security features enabled by the Weblogic Server.
  • If you are using the Oracle Fusion Midldeware , then it is recommended to use the Oracle JRockit JVM which has additional features added for SOA, BPEL, OSB and ADF
    objects to be released to garbage colllection and other service specific security features
  • The WebLogic Server Production Mode displays Warning messages for Demo SSL Certificate usage.
  • The Logs files in the WebLogic Server Production Mode supports file size of 500 KB and then New Log file will be created.
  • The WebLogic Server Production Mode always prompt for Weblogic User Name and Password.
  • The JDBC Connection Pool Capacity is Defaulted with 25 connections
  • The No. of threads available to Execute Queues are default to 25
  • Node manager user id and password are randomly generated
  • The DebugFlag is used to enable the WebLogic Workshop Debugger
  • Fast swap is disabled
  • Change center is Enabled and requires the Lock and Edit session
  • JRE Mode is -server, Server VM is tuned to maximize peak operating speed for executing long-running server applications, which requires high speed for fast start-up time or smaller runtime memory footprint.
    page_check_seconds in weblogic.xml file is -1 which means JSP pages will not be deployed
  • In The WebLogic Server Production Mode, server runs with all security configurations enabled

How to create a Durable Subscriber JMS Topic in Weblogic Server

WebLogic Server  durable subscriber JMS Topics, provides the persistent of the messages either file based or database specific until the message is delivered to the subscriber.  In case the message is failed, it is persisted in the database. Following are the parameters which are to be used for durable subscriber JMS Topic.

  • Client ID — The unique client ID  value for the created durable subscriber.
  • Subscription Name — The subscription name given to the durable subscriber.
  •  No Local — The noLocal flag for this durable subscriber, which when enabled, can prevent an application from receiving messages it has published itself.
  • Active — ensures that the subscription is used by a durable subscriber.
  • Selector — If specified, the message selector for filtering messages.
  • Messages Pending Count — The number of messages that are stored in the system but which are not visible.
  • Messages Current Count — The number of messages pending with the durable subscriber to be executed.
  • Bytes Current Count — The number of bytes received by the durable subscriber.

Steps to create a Durable Subscriber JMS Topic

1. Click on JMS Module. Select the created JMS Module in which JMS Topic is to be created.
2. Click on NEW to create a new JMS Topic.
3. Select Resource Type as ‘Distributed Topic’
4.  Provide JMS Topic Name
5. Provide JMS DataSource Name
6. Uncheck XA Connectory Factory ( this could depend on ur need)
7. Destination Type as – Uniform
8. Forwarding Polciy as – Partitioned
9. Target ( All Servers in Cluster)
10.  Save the JMS Topic.
11. Open the created JMS Topic and Click on Monitoring tab.
12. Click on Durable Subscriber Tab.
13. Click on Advance Tab
14. Provide the ClinetID value.
15. Provide the Subscription name.
16. Click on Apply to save the changes.


Increase queue length for Weblogic Server thread pool

The Weblogic Server uses the single thread pool for executing the system administrator or application activities.  Weblogic Server executes the received requests based on the maximum queue length defined for the thread pool. In case of exceeding this limit, WebLogic starts rejecting the web application requests.

We can avoid this by increasing the maximum queue length for the thread pool by making change in Environments > Servers > Threads -> Select an execute thread.
The default value for thread pool is 65536.

Reducing the HTTP Sessions
We can limit the number of HTTP sessions based on the memory allocation which avoids in resulting out of memory errors. The following entry can be done in deployment descriptor  file for handling count for HTTP sessions.
<session-descriptor>
<max-in-memory-sessions>10</max-in-memory-sessions>
</session-descriptor>

Exit from server  on Out of Memory exception
performing the exit when  out of memory exception occurs provides the automatic shutdown and configure the node manager or high availability tool to restart the weblogic server which reduces the down time for the server.

Add the below entry in the config.xml for automatic shutdown of server
<overload-protection>
<panic-action>system-exit</panic-action>
</overload-protection>


How to do a multiple composite deployment

The blog discuss the steps on “how to deploy the SOA Composites”, “multiple composite deployment in WebLogic Server” . The SOA Composites can be deployed, redeployed and undeployed using Ant and WLST scripts to the Weblogic SOA Server or it can be deployed using the WebLogic Administrator console. 

Point to Consider for SOA Composite deployment:

  • A new developed SOA Composite is deployed for the 1st time
  • A existing SOA Composite with the new revision(2.0) can be deployed. This will make a new deployment in SOA Server and will not impact the existing deployed SOA Composite(1.0)
  • Multiple SOA Composites can be deployed at once as part of single deployment process also called as SOA Bundle. The bundle can contains different revisions for different SOA Composites.

SOA Composite Deployment to WebLogic SOA Server

Perform the below given steps for SOA Composite deployment based on provided options

  • Log into the Weblogic em console for SOA applications

Navigate to SOA Infrastructure Menu

  • Select SOA Deployment > Deploy

Navigate to SOA Folder

  • Right-click soa-infra
  • Select SOA Deployment > Deploy

Navigate to SOA Infrastructure Home Page

  • Click the Deployed Composites tab.
  • Click Deploy

Navigate to SOA Composite Menu

  • Select SOA Deployment > Deploy Another Composite

From the above given options, the server navigates to the SOA Deployment Process

  • Archive or Exploded Directory -> browse the SOA composite application to deploy
  • Configuration Plan -> Select the configuration plan to deploy for SOA Composite application. The configuration plan provides the URL and property value based on deployment environment
  • Click Next
  • Select the WebLogic Server or Cluster for SOA Composite deployment
  • Click Next
  • Review the deployment details
  • Select whether to deploy the SOA composite application as the default revision
  • Click Deploy

Multiple SOA Composite Deployment to WebLogic SOA Server

Perform the below given steps for multiple SOA Composite deployment as part of SOA Bundle

  • 1. Select the Application Properties dialog, click Deployment.
  • 2. Click New and create a deployment Profile.
  • 3. Select SOA Bundle in the archive type list
  • 4. Provide a name in the name field and click OK.
  • 5. Select the dependencies node.
  • 6. Select the SARs that need to be included in the Bundle
  • 7. Click OK.
  • 8.  From the application menu, select Deploy -> <bundle_name>  and deploy to the Application Server Connection.

Redeploying SOA Composite to WebLogic SOA Server

Perform the below given steps for redeploying the SOA Composite in Weblogic Server based on provided options

  • Log into the Weblogic em console for SOA applications

Navigate to SOA Infrastructure Menu

  • Select SOA Deployment >Redeploy
  • SOA Composite Deployments -> Select the SOA Composite application revision
  • Click Next

Navigate to SOA Folder

  • Right-click soa-infra
  • Select SOA Deployment > Redeploy
  • SOA Composite Deployments -> Select the SOA Composite application revision
  • Click Next

Navigate to SOA Infrastructure Home Page

  • Click the Deployed Composites tab
  • Select the SOA Composite application revision
  • Click Deploy

Navigate to SOA Composite Menu

  • Select SOA Deployment > Redeploy

From the above given options, the server navigates to the SOA Deployment Process

  • Archive or Exploded Directory -> browse the SOA composite application to deploy
  • Configuration Plan -> Select the configuration plan to deploy for SOA Composite application. The configuration plan provides the URL and property value based on deployment environment
  • Click Next
  • Select the WebLogic Server or Cluster for SOA Composite deployment
  • Click Next
  • Review the deployment details
  • Select whether to deploy the SOA composite application as the default revision
  • Click Redeploy

Undeploying SOA Composite to WebLogic SOA Server

Perform the below given steps for undeploying the SOA Composite in Weblogic Server based on provided options

  • Log into the Weblogic em console for SOA applications

Navigate to SOA Infrastructure Menu

  • Select SOA Deployment >Undeploy
  • SOA Composite Deployments -> Select the SOA Composite application revision
  • Click Next

Navigate to SOA Folder

  • Right-click soa-infra
  • Select SOA Deployment > Undeploy
  • SOA Composite Deployments -> Select the SOA Composite application revision
  • Click Next

Navigate to SOA Infrastructure Home Page

  • Click the Deployed Composites tab
  • Select the SOA Composite application revision
  • Click Undeploy

Navigate to SOA Composite Menu

  • Select SOA Deployment > Undeploy

From the above given options, the server navigates to the SOA Deployment Process

  • Click Undeploy

How to set the production mode for weblogic domain

The blogs provides the steps on  how to set the production mode value in Weblogic Server

Points to Consider for Weblogic Server Production Mode

  • The WebLogic Server Production Mode does not support auto-deployment mode to reduce the overhead of continuous polling of directory updates. The deployments in the WebLogic Server are supported through Administration Console, weblogic.Deployer tool or the WebLogic Scripting Tool (WLST)
  • The Weblogic Server provides additional features when it is to be used for the production environment. The Weblogic Server production mode provides additional security features enabled by the Weblogic Server.
  • If you are using the Oracle Fusion Midldeware , then it is recommended to use the Oracle JRockit JVM which has additional features added for SOA, BPEL, OSB and ADF
    objects to be released to garbage colllection and other service specific security features
  • The WebLogic Server Production Mode displays Warning messages for Demo SSL Certificate usage. 
  • The Logs files in the WebLogic Server Production Mode supports file size of 500 KB and then New Log file will be created.
  • The WebLogic Server Production Mode always prompt for Weblogic User Name and Password.  
  • The JDBC Connection Pool Capacity is Defaulted with 25 connections
  • The No. of threads available to Execute Queues are default to 25
  • Node manager user id and password are randomly generated
  • The DebugFlag is used to enable the WebLogic Workshop Debugger
  • Fast swap is disabled
  • Change center is Enabled and requires the Lock and Edit session
  • JRE Mode is -server, Server VM is tuned to maximize peak operating speed for executing long-running server applications, which requires high speed for fast start-up time or smaller runtime memory footprint.
    page_check_seconds in weblogic.xml file is -1 which means JSP pages will not be deployed

How to set Production Mode value using the Weblogic Server administration  console.

Home-> Domain-> General -> Production Mode 

Set the value for Production Mode as TRUE.

Restart your server and it will runs with additional features including security. 

.

 


Caused By: java.net.SocketException: Write failed: Broken pipe

<oracle.adfinternal.view.faces.lifecycle.LifecycleImpl> <BEA-000000> <ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RENDER_RESPONSE 6
javax.faces.FacesException: Write failed: Broken pipe at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(LifecycleImpl.java:920)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:367)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:222)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)

at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused By: java.net.SocketException: Write failed: Broken pipe
at jrockit.net.SocketNativeIO.writeBytesPinned(Native Method)
at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)
at java.net.SocketOutputStream.socketWrite0(SocketOutputStream.java)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:568)
at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:539)

Solution:

The Broken Pipes messages are caused by applications taking more time to produce a response than Apache timeout. To solve this type of issues, the application needs to be tuned so that the response is provided before timeout fires. The Metalink Note (333862.1) provides the complete Solution.
If the application is OK and the response could not be delivered in a shorter time than Apache timeout, then increase the “Timeout” directive in the http.conf file. (The AS Control Console can be used for this purpose too).
1. In the AS control, select the HTTP Server component.
2. Then select properties.
3. Modify the timeout settings. Each unit represents a second. Default value is 300 (5 minutes).

For more details, refer Metalink Note (333862.1) related to this issue.


javax.faces.application.ViewExpiredException: – ADF_FACES-30107:The view state of the page has expired. Reload the page.

You need to define the value for org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS in the web.xml of your web application.

<context-param>
<description>Chooses how many tokens should be preserved at any one time.</description>
<param-name>org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS</param-name>
<param-value>50</param-value>
</context-param>


Caused By: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (APPS.PS_TXN_PK) violated oracle.jbo.PCollException: JBO-28030: Could not insert row into table PS_TXN

This might happen when you deploy another application in the same server environment where the already defined Transaction Id is again attempted to add in the existing table and violates the unique identity constraint. Reset the sequence number.

Other Useful links for the topic in discussion

http://docs.oracle.com/cd/E17904_01/web.1111/b31974/bcstatemgmt.htm#ADFFD1306

http://docs.oracle.com/cd/E17904_01/web.1111/b31974/bcstatemgmt.htm#ADFFD1307

http://docs.oracle.com/cd/E17904_01/core.1111/e10105/repos.htm#ASADM11531


Exception occured during invocation of JCA binding: “JCA Binding execute of Reference operation ‘insert’ failed due to: JCA Binding Component connection issue. JCA Binding Component is unable to create an outbound JCA (CCI) connection.

The blog discuss the common issue related to invocation of JCA binding in Weblogic Server.

Problem Statement:

JCA Binding execute of Reference operation ‘insert’ failed due to: JCA Binding Component connection issue

Cause for JCA Binding connection issue ?

The connection factory configured in Weblogic Server for the Database Adapter is not being defined with the data source value and due to that the run time connection issue occurs.

Solution Approach:

Perform the below given steps to resolve JCA Binding Component connection issue

  • Click on the Deployment
  • Click on the DBAdapter and it should have the status ACTIVE
  • Click on the Configurations
  • Click on the Outbound Connection Pools
  • Select the Connection Factory e.g eis/Apps
  • Check for the Property dataSource. If your DataSource is Non-XA then define the JNDI Name value and press ENTER
  • Check for the Property XADataSource . If your DataSource is XA then define the JNDI Name value and press ENTER
  • Click OK

Defining caching rules for images in the ADF Faces Caching Filter

<adf-faces-config xmlns=”http://xmlns.oracle.com/adf/faces/config”>

<caching-rules>
<caching-rule id=”cache js”>
<cache>true</cache>
<compress>true</compress>
<duration>99999</duration>
<agent-caching>true</agent-caching>
<cache-key-pattern>*.js</cache-key-pattern>
</caching-rule>

<caching-rule id=”cache jpeg”>
<cache>true</cache>
<compress>false</compress>
<duration>99999</duration>
<agent-caching>true</agent-caching>
<cache-key-pattern>*.jpeg</cache-key-pattern>
</caching-rule>

<caching-rule id=”cache png”>
<cache>true</cache>
<compress>false</compress>
<duration>99999</duration>
<agent-caching>true</agent-caching>
<cache-key-pattern>*.png</cache-key-pattern>
</caching-rule>

<caching-rule id=”cache PNG”>
<cache>true</cache>
<compress>false</compress>
<duration>99999</duration>
<agent-caching>true</agent-caching>
<cache-key-pattern>*.PNG</cache-key-pattern>ion
</caching-rule>

<caching-rule id=”cache css”>
<duration>99999</duration>
<agent-caching>true</agent-caching>
<cache-key-pattern>*.css</cache-key-pattern>
</caching-rule>

</caching-rules>
</adf-faces-config>