Object or Statement Block locking using synchronized keyword in java
Hi ,
Can anyone tell me how java is implementing the Object locking and the code block locking mechanism using the 'synchronized' keyword internally??
Thanks in advance
Raj
The JVM implements a concept known as a monitor using a combination of direct implementation and support by the operating system. For more detail, refer to the Java JVM and language specifications.
Chuck
Similar Messages
-
Can i make Thread safe without using synchronised keyword in java
Hi all,
please tell me code and concept that we can make Thread safe without using synchronised keyword in java programming.
regards
Mohan kumarThere's a series of new features in Java 5.0 (JDK 1.5.0) to address things like concurrency.
See: http://java.sun.com/j2se/1.5.0/docs/guide/concurrency/overview.html
-Alexis -
How to use Synchronized Keyword
Hi guys,
Sorry if this is a simple question, but I'm not sure about the following:
Suppose we have the class,
Class Foo
public synchronized void bar1() {...}
public synchronized void bar2() {...}
If I have two threads running concurrently, say T1 and T2.
I know that T1 and T2 can't both be in bar1() at the same time right? [It has to be in some serial order]
But, can T1 be in bar1() and T2 be in bar2() at the same time?
I guess the question is, does the synchronized apply to that specific method only? Or rather to the object (which basically limits at most one thread calling that object's synchronized methods)?
Thanks a bunch! :)
-Michael.Hi Michael,
In general, when you syncronize a block of code, the execution of the block is syncronized ON an object. Any object can function as a lock, and only one thread can have a lock of one object at a time. If one thread already has a lock on an object and another thread tries to acquire lock on the same object, the latter thread will wait until the lock is released.
When you use 'synchronized' in method declaration, it means that the execution of the whole method is syncronized on the object itself (NOT class, if the method is non-static. Static method would be synchronized on the .class object.)
So, if you have more than one syncronized methods, only one of them is executed at a time ON THE SAME OBJECT. The same method can, of course, be executed simultaneously on other objects. Also, if some of the methods are synchronized, but other methods are not, the non-synchronized methods are not affected in any way.
It might be good to note that these two pieces of code have exactly the same meaning:
public synchronized doSomething() {
// do something
}and
public doSomething() {
synchronized (this) {
// do something
}Hope this helps.
Cheers,
Vesa
p.s. It's a good idea to design your code so that one thread will have no more than one lock at a time. If it's possible for more than one thread to have lock on more than one object, there may be a risk of the threads dead-locking, which will crash any program... -
How to Use native keyword in java programming
Hi ,
I am using JDK 1.6.0_11 , and i was trying to create a java program using "native" keyword ,
i got the sample code for the same from the site : - http://www.javaworld.com/javaworld/javatips/jw-javatip23.html
But when i type this command " C:\javah -stubs Happy " following error occurs
" Error: JNI does not require stubs, please refer to the JNI documentation. "
then typed " c:\javah -jni Happy" without any error .
After that i wrote a HappyImpl.c as mentioned in the above tutorial
#include <StubPreamble.h> /* Standard native method stuff. */
#include "Happy.h" /* Generated earlier. */
#include <stdio.h> /* Standard C IO stuff. */
void Happy_printText (struct HHappy *this)
puts ("Happy New Year!!!");
then it is not compling and error is
"unable to open included file StubPreamble.h file
unable to open included file Happy.h file "
Please help me . i want to use native method , i did exactly the same in tutorial at above link.
Thanks & Regards
Mannatyou do need to know how to use your C compiler... It quite clearly can't find those files which indicates that you didn't tell it where to find them.
-
Shall I use synchronized keyword?
Hi there!
I have made a small client-server applikation with RMI.
The server has a connection to a database (only one connection). On the server I have also placed the SQL-queries in separate methods that can be invoced from the clients. The question is:
Do I have to sychronize these methods that access the databse from the one and only database connection? Or can several clients that invoce the same method simultanously use the same one and only database connection?
Thanks in advance!
/MackanAccording to my experience, the connection can be shared among multiple threads, but the statements and resultsets must be in method scope.
-
Oracle deadlock - how to use "synchronised" keyword in a transaction?
Hi,
I use WL6.1 SP4, Oracle 8.1.6, with some Java objects which execute a
lot
of SQL queries (mixed update, insert and select) using plain JDBC
calls,
and Weblogic connection pools. These objects are called by servlets.
I experienced recently deadlocks when two users call the object at the
same
time (See error below).
I execute the queries using "synchronized" keyword in the following
way:
synchronized (this)
conConnection.setAutoCommit(false);
executeTransaction(myStatement);
conConnection.commit();
executeTransaction is overriden in sub-classes and is the method which
executes
all the queries.
It calls methods in other objects. These methods are not declared as
synchronized.
1) Should they?
2) Should I use the keyword "synchronized" in another way?
3) This part of code is also called when I do only "select"
statements. I guess
it should only be synchronized when we do "update" and "insert" which
could lead
to a deadlock?
4) Do you have any idea why this deadlock occurs as I use the
"synchronized"
keyword, and one thread should wait until the other one has finished?
Thanks for any idea,
Stéphanie
----------------- error:
<ExecuteThread: '4' for queue: 'default'> <> <> <000000> <SQL request
sent to database: UPDATE PARTICIPANT par SET par.PARTICIPANTLASTRANK =
4 WHERE par.IDPARTICIPANT = 8983566>
<ExecuteThread: '11' for queue: 'default'> <> <> <000000> <SQL request
sent to database: UPDATE PARTICIPANT par SET par.PARTICIPANTLASTRANK =
6 WHERE par.IDPARTICIPANT = 8983570>
ORA-00060: deadlock detected while waiting for resource
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:796)
at weblogic.jdbc.pool.Statement.executeUpdate(Statement.java:872)
at weblogic.jdbc.rmi.internal.StatementImpl.executeUpdate(StatementImpl.java:89)
at weblogic.jdbc.rmi.SerialStatement.executeUpdate(SerialStatement.java:100)
at bfinance.framework.EDBBLBean.executeSQL(EDBBLBean.java:299)Hi Stepanie,
I'd try to group update statement together. Usually it helps.
Regards,
Slava Imeshev
"Stephanie" <[email protected]> wrote in message
news:[email protected]...
Thanks for your answer.
In the case you describe, is there a way to ensure that tx-2 waits for
tx-1
to be finished before beginning?
My transaction which causes the problem is the following (simplified):
UPDATE tableA SET islast=0 WHERE externalid=myid;
for (int i=0; i< aVector.size(); i++) {
INSERT INTO tableA (id, islast, ranking, externalid) (SELECT
SEQ_tableA.nextval, 1, 0, myid);
UPDATE tableA SET ranking = /*calculated ranking */
WHERE externalid=myid AND islast=1;
UPDATE tableB ....
commit;
tx-1 and tx-2 execute this transaction at the same time. tx-1 begins
The deadlock appears when tx-2 executes the second UPDATE tableA
query.
I don't see how I can avoid to execute these two update queries, so if
I can find another way to prevent deadlock, it would be great!
Stéphanie
Joseph Weinstein <[email protected]_this> wrote in message
news:<[email protected]_this>...
Stephanie wrote:
Hi,
I use WL6.1 SP4, Oracle 8.1.6, with some Java objects which execute a
lot
of SQL queries (mixed update, insert and select) using plain JDBC
calls,
and Weblogic connection pools. These objects are called by servlets.
I experienced recently deadlocks when two users call the object at the
same
time (See error below).Hi. The error you are getting isn't necessarily from a lack ofsynchronization
of your java objects. It has to do with the order in which you accessDBMS
data. You are getting ordinary DBMS deadlocks, which are caused when
two DBMS connections each have a lock the other wants, in order toproceed.
The DBMS will quickly discover this and will kill one transaction inorder to
let the other one proceed:
time 0: tx-1 and tx-2 have started.....
time 1: tx-1: update tableA set val = 1 where key = 'A'
time 2: tx-2: update tableB set val = 2 where key = 'B'
time 3: tx-1: update tableB set val = 1 where key = 'B' (waitsbecause tx-2 has the row
locked)
time 4: tx-2: update tableA set val = 2 where key = 'A' (waitsbecause tx-1 has the row
locked)
This is a deadlock. The solution is to organize your application code sothat every
transaction accesses the data in the same order, eg: update tableAfirst, then update tableB.
This will prevent deadlocks.
Joe Weinstein at BEA
I execute the queries using "synchronized" keyword in the following
way:
synchronized (this)
conConnection.setAutoCommit(false);
executeTransaction(myStatement);
conConnection.commit();
executeTransaction is overriden in sub-classes and is the method which
executes
all the queries.
It calls methods in other objects. These methods are not declared as
synchronized.
1) Should they?
2) Should I use the keyword "synchronized" in another way?
3) This part of code is also called when I do only "select"
statements. I guess
it should only be synchronized when we do "update" and "insert" which
could lead
to a deadlock?
4) Do you have any idea why this deadlock occurs as I use the
"synchronized"
keyword, and one thread should wait until the other one has finished?
Thanks for any idea,
Stéphanie
----------------- error:
<ExecuteThread: '4' for queue: 'default'> <> <> <000000> <SQL request
sent to database: UPDATE PARTICIPANT par SET par.PARTICIPANTLASTRANK =
4 WHERE par.IDPARTICIPANT = 8983566>
<ExecuteThread: '11' for queue: 'default'> <> <> <000000> <SQL request
sent to database: UPDATE PARTICIPANT par SET par.PARTICIPANTLASTRANK =
6 WHERE par.IDPARTICIPANT = 8983570>
ORA-00060: deadlock detected while waiting for resource
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
atoracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
atoracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
atoracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047
atoracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
atoracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java
:2709)
atoracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:796)
atweblogic.jdbc.pool.Statement.executeUpdate(Statement.java:872)
atweblogic.jdbc.rmi.internal.StatementImpl.executeUpdate(StatementImpl.java:89
atweblogic.jdbc.rmi.SerialStatement.executeUpdate(SerialStatement.java:100)
at bfinance.framework.EDBBLBean.executeSQL(EDBBLBean.java:299) -
Select statement inside function with into keyword
Hi Everyone,
i have a function which contains a select statement
create or replace
function fun_1(Table_Name1 in varchar2)
RETURN VARCHAR2
is
VAR_GEN_TYPE NUMBER(10);
TA_U varchar2(256);
VAR_DATA_FLAG varchar2(1);
begin
select T.FLAG into VAR_GEN_TYPE ,T.DATA_UID_GEN_TYPE into VAR_DATA_FLAG from T_DYNAMIC_TABLE T where T.TABLE_NAME=TABLE_NAME1;
end
whene ever i am executing this function giving error message: From Keyword Not Found
when i change select statement to
select T.FLAG ,T.DATA_UID_GEN_TYPE into VAR_DATA_FLAG, VAR_GEN_TYPE from T_DYNAMIC_TABLE T where T.TABLE_NAME=TABLE_NAME1;
then it is working
why first statements will not work ?
i.e.,
select T.FLAG into VAR_GEN_TYPE ,T.DATA_UID_GEN_TYPE into VAR_DATA_FLAG from T_DYNAMIC_TABLE T where T.TABLE_NAME=TABLE_NAME1;
why in select statement we cannot use into keyword more than one time ?
Edited by: karteek on Jun 7, 2012 4:23 AM
Edited by: karteek on Jun 7, 2012 4:24 AMselect T.FLAG into VAR_GEN_TYPE ,T.DATA_UID_GEN_TYPE into VAR_DATA_FLAG, from T_DYNAMIC_TABLE T where T.TABLE_NAME=TABLE_NAME1;
into should be only once..
the syntax should be
select <column list>
into
<variable list>
from <table name> where <condition>
--This query shuold return only one row.
column list count and variable list count should match
there should be no comma after last variable.andbefore from. -
Synchronized keyword for simple addition
Hi, I have a function, as given below
{noformat}public static void increment() {{noformat}{noformat} a = a + 1; {noformat}{noformat}}
{noformat}
This function will be called from multiple threads (a is also a static variable).
My question is should I use "synchronized" keyword for this method to avoid unpredictable results? Is there a way to wirte this function without using "synchronized" keyword?
Please suggest.Thanks, jwenting. I wanted to confirm that "synchronized" has to be used.
jwenting wrote:
yes. Depending of course on what you decide to be "unpredictable" :)you understand what "unpredictable" means here ;)
jwenting wrote:
yes, don't use a static variable but a method local one. Of course that will have a totally different effect.Variable "a" should be a class level variable. Yes, local variable has a totally different effect. ;) -
Multiple blocking locks on same object
we have a database that is providing a great deal of application 'freezing' due to lock problems that were not experienced before moving to a new 10g database environment.
one of the items i believe to be of interest is the fact that when this 'freezing' occurs then a look at the database locks reveals that more than one TX exclusive blocking lock is held on the same database object without any waits showing.
my understanding is that this should not be the case? that only one user should possess the exclusive transaction level lock and that the other user should only have an outstanding request for this same level lock?
any information you can provide would be most appreciated.
thanks in advance.You would need to find out the sql the application is executing when those locks freeze like that. From there determine if there is a logical syntax issue or get the explain plan to ensure it isn't for example an update statement on a massive table that has improper indexing.
Also, do you see other sessions blocking other sessions as orafad suggested? In this scenario my original explanation is different. If the locks are all chained on waiting on another session, that means the first session that is blocking is updating the same data that the waiters are wanting.
In my opinion you need to find out the exact SQL causing these locks to ensure it is an issue with one of your applications. Determining the performance of that query is a must.
The only weird thing is you say there is no waits taking place....did you look in v$session_wait?
Lee -
Use of synchronized keyword with portal services
Hi,
Can you confirm me if it is true that a portal service is a Singleton? I mean, when using an instance variable of a portal service I am able to set the value of the instance variable using one client app and get it afterwards using another client app. So we are talking about the same and only instance of the portal service, right?
If this is true how can I synchronize the access to a portal's service method? I tried to mark
the method syncronized (in the interface) but then I realized that this issues a compiler error because one can not mark an interface method synchronized. So can I mark the implementation class instead? That is, can I leave the interface without the synchronized keyword for the method and still mark the implementation of the method in the service class as syncronized? Does this work?
Thanks in advance,
DizHi,
Portal service is not a Singleton, as the name says a service is just provider for services which does not save state between two requests/applications.
So if you want to save state, then use some session variables to save it.
In a cluster installation, each server node has its own portal services, so if you save state in service, then your application should save this state on all servers of the cluster.
So you should change your approch.
http://help.sap.com/saphelp_nw70/helpdata/en/e3/fab74247e2b611e10000000a155106/frameset.htm
Greetings,
Praveen Gudapati
[Points are always welcome for helpful answers] -
Use of Synchronized Keyword / Concurrency
I have a program which makes two Writer threads (they add 1 to a shared
counter), A sampler Thread (like a reader thread � it also displays the
data held by the other thread). I have been playing around with the
synchronised keyword � but I am not sure how to interpret the
results..I'll post the code first....
the shared counter------------------------------
package sycTest;
public class Counter
{public int val = 0;}
the sampler / reader class----------------------
package sycTest;
public class Sampler extends Thread
private Counter c;
private MyThread A, B;
public Sampler ( MyThread A, MyThread B, Counter c ) {
this.A = A;
this.B = B;
this.c = c;
public void run()
while(true)
try { sleep( 1000 ); } catch (Exception x) { }
System.out.println
"A count = " + A.getCount() + ", " +
"B count = " + B.getCount() + ": " +
"A + B count = " + (A.getCount() + B.getCount()) + ", " +
"shared counter = " + c.val
the main class to get things started------------------------------------
package sycTest;
import java.util.Random;
public class Main
public static void main( String[] args )
Counter c = new Counter();
MyThread A = new MyThread( c );
MyThread B = new MyThread( c );
A.start(); B.start();
// create and start Sampler thread in one step
new Sampler( A, B, c ).start();
// main thread waits to read a carriage-return.
try {
System.in.read();
catch( Exception e ) { }
System.exit(0);
/* rand_sleep function is used to generate "random switching" behaviour
assuming n > 0,
rand_sleep( n ) sleeps a random time between 0 and n millisec.
private static Random rand = new Random();
public static void rand_sleep( int maxms ) {
int ms = rand.nextInt() % maxms; // - maxms < ms < maxms
int amt=(ms + maxms + 1)/2;
try { Thread.sleep(amt); } catch(Exception e) { }
the thread / writer class-------------------------------------------
package sycTest;
public class MyThread extends Thread
private Counter sharedCounter;
public MyThread( Counter c ) { this.sharedCounter=c; }
private int count=0;
public int getCount() { return count; }
public void run() {
while(true)
// simulate non-critical section by sleeping a "large" amount
Main.rand_sleep(1000);
synchronized (sharedCounter) {
criticalSection();
//Main.rand_sleep(1000);
++count;
private void criticalSection() {
int x=sharedCounter.val + 1;
Main.rand_sleep( 100 );
sharedCounter.val=x;
--the question!
The idea is that running the main methods gives something like
A count=13, B count=10: A + B count=23, shared counter=23
(where A and B are writer threads)
If I take out the synchronised keyword in the MyThread class, things get
much worse...the 'personal' totals of A and B do not equal the total
held in the shared counter rather quickly..
criticalSection();
//Main.rand_sleep(1000);
++count;
eg
A count=13, B count=10: A + B count=23, shared counter=22
However, adding the synchronised keyword (eclipse suggested
�sharedCounter� as the argument � the notes seem to suggest �this�, but
if I do that the synchronised keyword seems much like the example above...
synchronized (sharedCounter) {
criticalSection();
++count;
this makes it much better...I never saw it get the counts 'wrong'
eg
A count=56, B count=72: A + B count=128, shared counter=128
Now comes the confusing bit...when I add some time between the 2 methods
within the sychonized block...
synchronized (sharedCounter) {
criticalSection();
Main.rand_sleep(1000);
++count;
Then mismatches appear very quickly, the program behaves very similarly
to when it didn't have the synchronised keyword...
Why is this? Is it because the Sampler class is asking what the values
of the shared and personal counters during the �Main.rand sleep(1000)�
call??
The other question I was hoping someone could help me with, is pointing
out what the difference is between �synchronized (sharedCounter)� and
�synchronized (this)� is in this context. Why does the later not do
anything in this example?
Thanks,
JulianHello Julian,
you're Sampler thread reads the different counters without any synchronization. He may call A.getCount() and get 5 back, then yield and then ask for c.val which was increased by A in the meantime. Or A increases it's own counter, then yields and lets the Sampler output nonsense.. ;)
To clear up the confusion surrounding Thread.sleep(long): It would be a waste to do nothing while the thread is sleeping, so another thread gets to play. Since the other MyThread is waiting on sharedCounter's monitor and the sleeping thread still owns it<sup>1</sup> the Sampler thread gets the execution time. Now the sampler gets going and you know the rest.
1: http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.9
EDIT: In future, use code-tags:
class MyClass {
private int myField;
}will turn into
class MyClass {
private int myField;
}With kind regards
Ben
Edited by: BenSchulz on Mar 24, 2008 11:45 AM -
Using OleDbDataAdapter Update with InsertCommands and getting blocking locks on Oracle table
The following code snippet shows the use of OleDbDataAdapter with InsertCommands. This code is producing many inserts on the Oracle table and is now suffering from contention... all on the same table. How does the OleDbDataAdapter produce
inserts from a dataset... what characteristics do these inserts inherent in terms of batch behavior... or do they naturally contend for the same resource.
oc.Open();
for (int i = 0; i < xImageId.Count; i++)
// Create the oracle adapter using a SQL which will not return any actual rows just the structure
OleDbDataAdapter da =
new OleDbDataAdapter("SELECT BUSINESS_UNIT, INVOICE, ASSIGNMENT_ID, END_DT, RI_TIMECARD_ID, IMAGE_ID, FILENAME, BARCODE_LABEL_ID, " +
"DIRECT_INVOICING, EXCLUDE_FLG, DTTM_CREATED, DTTM_MODIFIED, IMAGE_DATA, PROCESS_INSTANCE FROM sysadm.PS_RI_INV_PDF_MERG WHERE 1 = 2", oc);
// Create a data set
DataSet ds = new DataSet("documents");
da.Fill(ds, "documents");
// Loop through invoices and write to oracle
string[] sInvoices = invoiceNumber.Split(',');
foreach (string sInvoice in sInvoices)
// Create a data set row
DataRow dr = ds.Tables["documents"].NewRow();
... map the data
// Populate the dataset
ds.Tables["documents"].Rows.Add(dr);
// Create the insert command
string insertCommandText =
"INSERT /*+ append */ INTO PS_table " +
"(SEQ_NBR, BUSINESS_UNIT, INVOICE, ASSIGNMENT_ID, END_DT, RI_TIMECARD_ID, IMAGE_ID, FILENAME, BARCODE_LABEL_ID, DIRECT_INVOICING, " +
"EXCLUDE_FLG, DTTM_CREATED, DTTM_MODIFIED, IMAGE_DATA, PROCESS_INSTANCE) " +
"VALUES (INV.nextval, :BUSINESS_UNIT, :INVOICE, :ASSIGNMENT_ID, :END_DT, :RI_TIMECARD_ID, :IMAGE_ID, :FILENAME, " +
":BARCODE_LABEL_ID, :DIRECT_INVOICING, :EXCLUDE_FLG, :DTTM_CREATED, :DTTM_MODIFIED, :IMAGE_DATA, :PROCESS_INSTANCE)";
// Add the insert command to the data adapter
da.InsertCommand = new OleDbCommand(insertCommandText);
da.InsertCommand.Connection = oc;
// Add the params to the insert
da.InsertCommand.Parameters.Add(":BUSINESS_UNIT", OleDbType.VarChar, 5, "BUSINESS_UNIT");
da.InsertCommand.Parameters.Add(":INVOICE", OleDbType.VarChar, 22, "INVOICE");
da.InsertCommand.Parameters.Add(":ASSIGNMENT_ID", OleDbType.VarChar, 15, "ASSIGNMENT_ID");
da.InsertCommand.Parameters.Add(":END_DT", OleDbType.Date, 0, "END_DT");
da.InsertCommand.Parameters.Add(":RI_TIMECARD_ID", OleDbType.VarChar, 10, "RI_TIMECARD_ID");
da.InsertCommand.Parameters.Add(":IMAGE_ID", OleDbType.VarChar, 8, "IMAGE_ID");
da.InsertCommand.Parameters.Add(":FILENAME", OleDbType.VarChar, 80, "FILENAME");
da.InsertCommand.Parameters.Add(":BARCODE_LABEL_ID", OleDbType.VarChar, 18, "BARCODE_LABEL_ID");
da.InsertCommand.Parameters.Add(":DIRECT_INVOICING", OleDbType.VarChar, 1, "DIRECT_INVOICING");
da.InsertCommand.Parameters.Add(":EXCLUDE_FLG", OleDbType.VarChar, 1, "EXCLUDE_FLG");
da.InsertCommand.Parameters.Add(":DTTM_CREATED", OleDbType.Date, 0, "DTTM_CREATED");
da.InsertCommand.Parameters.Add(":DTTM_MODIFIED", OleDbType.Date, 0, "DTTM_MODIFIED");
da.InsertCommand.Parameters.Add(":IMAGE_DATA", OleDbType.Binary, System.Convert.ToInt32(filedata.Length), "IMAGE_DATA");
da.InsertCommand.Parameters.Add(":PROCESS_INSTANCE", OleDbType.VarChar, 10, "PROCESS_INSTANCE");
// Update the table
da.Update(ds, "documents");Here is what Oracle is showing as blocking locks and the SQL that has been identified with each of the SIDS. Not sure why there is contention. There are no triggers or joined tables in this piece of code.
Here is the SQL all of the SIDs below are running:
INSERT INTO sysadm.PS_RI_INV_PDF_MERG (SEQ_NBR, BUSINESS_UNIT, INVOICE, ASSIGNMENT_ID, END_DT, RI_TIMECARD_ID, IMAGE_ID, FILENAME, BARCODE_LABEL_ID, DIRECT_INVOICING, EXCLUDE_FLG, DTTM_CREATED, DTTM_MODIFIED, IMAGE_DATA, PROCESS_INSTANCE) VALUES (SYSADM.INV_PDF_MERG.nextval,
:BUSINESS_UNIT, :INVOICE, :ASSIGNMENT_ID, :END_DT, :RI_TIMECARD_ID, :IMAGE_ID, :FILENAME, :BARCODE_LABEL_ID, :DIRECT_INVOICING, :EXCLUDE_FLG, :DTTM_CREATED, :DTTM_MODIFIED, :IMAGE_DATA, :PROCESS_INSTANCE)
SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1150 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1
SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1
SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1156 (BTSUSER,biztprdi,BTSNTSvc64.exe) in instance FSLX3
SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 6 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX2
SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1726 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX2
SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 2016 (BTSUSER,biztprdi,BTSNTSvc64.exe) in instance FSLX2 -
How to use lock object? what we lock either total ztable or only record?
Hi
How to use lock object? what we lock either total ztable or only particular record?
Don't tell create lock object on se11 with E letter & acll it in program with eENQUEUE & DEQUEUE.
just tell me we will lock only particular record or total ztable?
specify with example.
Thanks.Hi
Go to SE11, in the option 'Lock object' enter the name of your lock,
begin with 'E', suppose 'EXXXX' And create. In tab 'Tables' fill the
table name where the record you want to lock exist and select the
lock mode. Lock mode can be shared and exclusive. If 'shared',
when you lock the record, other can also read data, but can not
modify. If 'exclusive', when you lock the record, other can neither
read nor modify the record. After save and activate, you will get two
function module.'ENQUEUE_EXXXX' to lock record,
'DEQUEUE_EXXXX' to release lock on one record.
When use this function module it only lock one record at a time. It
does not lock the table. -
Why use synchronized to decorate an object which its type is Vector
Hello,guys.
Recently,I readed the source code of java.util.Observable.Unfortunately,I encounted some problems。In the source code ,there is an object named obs.Its type is Vector. As we all know,Vector is thread-safe.why use synchronized in below code?
public synchronized void deleteObservers() {
obs.removeAllElements();
}thanks.
Edited by: qiao123 on Dec 21, 2009 7:07 PMMy " NewBie" Definition of Thread Safe :Is of no interest. It already has a definition and that isn't it.I wanted to make clear what my definition is.
The [JLS DEF FOR COLLECTION|http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html] says:
That is the Javadoc for Collections actually, nothing to do with the JLS or Collection.They are authoritative links for Java Language and the discussion in hand, not Fantasies of Lucy Aunty.
So,how do we draw any inference(s) here?Yes, that you have selectively quoted the Javadoc, which goes on to talk about how you have to use it when iterating.Still not answering my question,Sir.
ejp,you seem to have knowledge but you don't have the attitude to forward the same to others or bear what others say,even when initiative has been taken by others to put forward a problem.
P.S : Not all hackers are arrogant and not all arrogant are hackers.
Another P.S : Waste of my time really !!!
Edited by: punter on Dec 22, 2009 1:09 AM -
Can a object created using static keyword be recreated? Singleton Pattern
Hi All
To implement a Singleton I can use the following code
public Singleton {
private Singleton(){
private static final s_instance = new Singleton();
public Singleton getInstance(){
return s_instance;
Now if the Class Singleton gets unloaded during a program execution and again get loaded won't s_instance be recreated? If my question is correct this would lead to be leading to a new Singleton class instance with all the original variables.
Having answered the above question if I lazily initialize my Singleton using the following code won't the above problem still occur.
public Singleton {
private Singleton(){}
private final volatile Singleton s_instance = null;
public Singleton () {
if(s_instance != null) {
synchronized (s_instance) {
s_instance = new Singleton();
return s_instance;
Having answered all the above questions what is the best way to write a Singleton?Would the class get unloaded even if the Singleton object has some valid/reachable references pointing to it?
On a different note, will all the objects/instances of a class get destroyed if the class gets unloaded.That's the other way round, really: instances cannot be garbage-collected as long as they are strongly reachable (at least one reference pointing to them), and classes cannot be unloaded as long as such an instance exists.
To support tschodt's point, see the JVM specifications: http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#32202
*2.17.8 Unloading of Classes and Interfaces*
A class or interface may be unloaded if and only if its class loader is unreachable. The bootstrap class loader is always reachable; as a result, system classes may never be unloaded.
Will the same case (Custom ClassLoader getting unloaded) occur if I write the singleton using the code wherein we lazily initialize the Singleton (and actually create a Singleton instance rather than it being a Class/static variable).You should check the meaning of this vocabulary ("object", "instance", "reference"): http://download.oracle.com/javase/tutorial/java/javaOO/summaryclasses.html
The difference between the lazy vs eager initializations is the time when an instance is created. Once it is created, it will not be garbage collected as long as it is reachable.
Now I'm wondering, whether being referenced by a static attribute of a class guarantees being reachabe. I'm afraid not (see the JLS definition of reachable: http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44762). That is, again, unless the class has been loaded by the system class loader.
Maybe you are looking for
-
Any help with easy to understand directions would be greatly appreciated. So far I have not been able to understand forum threads. Thank you!
-
My subscription is expired how can I renew it?
I downloaded and installed creative cloud to access photoshop but when I click on the photoshop icon, a notification comes up saying I need to renew my subscription. How do I access the app?
-
How to restrict "insert new data source" in Analysis, edition for Microsoft Office report
Hi Experts, There is a requirement in my current project: when an end user access a Analysis, edition for Office Report from BI platform, they can view and refresh the report. But users should not be able to add new data source in that Analysis Repor
-
I have a brand new iMac 27" with the latest version of FCPX installed. I am trying to import the media from the 32GB flash card from a Canon XF100. FCPX does not recognize the media. I researched many threads, all leading me to download a Canon XF
-
Job that never finishes in the Batch Apps Service?
We have a job that never finishes, the single task that it runs says it's finished but the job never ends. I end up having to cancel it. The task that runs takes about 33 minutes or so to complete. Could whatever that monitors the job timeout waiting