Correct way to handle the updated object

Hi,
I have a thread, test2.java, that periodically update a object that pass from test.java. In test.java, the "data" object need to be most updated coz this object is used in other thread also. I can ensure that only test2.java do the write, others threads are read only.
My question is: I can write some dirty code to do what I want. But for a programmer, I want to know the formal, oo way to handle this situation.
Thanks.
Tommy
public class test{
data d;
test2 t2;
public test(){
d = new data(1, getClass().toString());
t2 = new test2(d);
t2.start();
public void runServices(){
while(true){
//If i don't do anything, the following code only print out
//the instance that i init. here.. Not the updated one
System.out.println(d.toString());
try{
Thread.sleep(5000);
}catch(InterruptedException ex){}
public static void main(String[] args){
test t = new test();
t.runServices();
* This class will periodically update the "data" object that
* passed from test.java
public class test2 extends Thread{
int count = 1;
data d;
public test2(data a){
this.d = a;
public void run(){
while(true){
d = new data(count++, getClass().toString());
System.out.println(d.toString());
try{
sleep(5000);
}catch(InterruptedException ex){}
public class data{
int count;
String s = "";
public data(int a, String b){
count = a;
s = b;
public String toString(){
return s + " count:" + count;

Sorry nearly missed that :(
You should try to modify the instance of data you have been given in the constructor for test2 instead of creating a new object:
* This class will periodically update the "data" object that
* passed from test.java
public class test2 extends Thread {
  int count = 1;
  data d;
  public test2(data a) {
    this.d = a;
  public void run() {
    while(true) {
      d.refreshWith(count++, getClass().toString());
      System.out.println(d.toString());
     try {
       sleep(5000);
     } catch(InterruptedException ex){}
}

Similar Messages

  • What's the correct way to do the update of AddOn

    Hi,
    Let's say I install the Add-On on server and pushed to each client, if I have to change something in AddOn, do I need to unstall this Add-ON and wait till all clients uninstall current AddOn and then i deploy new version to server and each client has to install the new AddOn again? Is this usual way to do the update of AddOn ?
    Thanks!
    Lan

    Hi Gordon,
    Ok, Thanks!
    P.S. But why SAP B1 doesn't check each Add-On ver # in server side when each time it is launched on client side, If the AddOn has new version, then download it and reinstall it. That's more smart!
    Lan

  • I downloaded ios5.1.1 to my phone, but i dont like the new software. The face detection used in the camera jut isnt for me. So, i would like to know if there was a way to undo the update and go back to ios 5.0.1. My iphone is not jailbroken or unlocked.

    i downloaded ios5.1.1 to my phone, but i dont like the new software. The face detection used in the camera jut isnt for me. So, i would like to know if there was a way to undo the update and go back to ios 5.0.1. My iphone is not jailbroken or unlocked.

    The face detection used in the camera jut isnt for me.
    Try a different camera app.  Camera Plus is a good one and there are many others.

  • HT4972 I replaced the computer I originally used to synch my iPhone. I get the message stating that my content will be erased, even though this is the computer I now synch with. Is there a way to make the update recognize the new computer?

    I replaced the computer I originally used to synch my iPhone. When trying to update to iOS5.0, I get the message stating that my content will be erased, even though this is the computer I now synch my phone with. Is there a way to make the update recognize the new computer so that my content will be kept?

    The best option is to copy your entire iTunes folder from your old computer to your new one using one of the methods described here: http://support.apple.com/kb/HT4527.  This will allow iTunes on your new computer to recognize and sync with your phone without deleting content.  You will also need to copy over any other synced data not in your iTunes library such as photos synced to your phone, calendars and contacts.
    If you can't do this, these articles will help you start syncing with your new computer with minimal or no data loss:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive
    Recovering your iTunes library from your iPod or iOS device

  • What's the best way to handle the growth of the mdm.tblTransaction table?

    Can anyone suggest a good way to handle the growth of the mdm.tblTransaction table? This table logs all the MDS transactions and the history of the data residing in it is required for auditing purposes. Hence we can't delete this data. I'm looking for options
    on how we can maitain this table ongoing. It is going to perform badly eventually. We currently have 15 Million transactions in this table.
    What options can we look at?

    In the vnext sql server, MDS will support cleaning based on log retention policy.
    In the sql2014/sql2012, you have to clean up the table manually.
    An sample sproc that can be reused is attached below.
    ==============================================================================
    Copyright (c) Microsoft Corporation. All Rights Reserved.
    ==============================================================================
    SELECT * FROM mdm.tbl_7_TR where LastChgDTM < '2014-10-22';
    EXEC mdm.udpLogCLeanup 7, '2014-10-22';
    SELECT * FROM mdm.tbl_7_TR where LastChgDTM < '2014-10-22';
    CREATE PROCEDURE mdm.udpTransactionsCleanup
    @Model_ID INT,
    @CleanupOlderThanDate DATE
    WITH EXECUTE AS N'mds_schema_user' -- Execute as a user that has permission to select on [tblUserGroupAssignment], [tblBRBusinessRule], [udfSecurityUserBusinessRuleList]
    AS BEGIN
    SET NOCOUNT ON
    DECLARE
    @SQL NVARCHAR(MAX)
    --Annotation table names
    ,@TransactionTableName sysname
    ,@AnnotationTableName sysname;
    SET @TransactionTableName = 'tblTransaction';
    SET @AnnotationTableName = 'tblTransactionAnnotation';
    BEGIN TRY
    --Delete all Annotations on transactions being deleted issues
    SET @SQL = N'
    DELETE [mdm].' + QUOTENAME(@AnnotationTableName) + N'
    FROM [mdm].' + QUOTENAME(@AnnotationTableName) + N' as tannt
    JOIN [mdm].'+ QUOTENAME(@TransactionTableName) + N' as txn ON tannt.Transaction_ID = txn.ID
    JOIN [mdm].[tblModelVersion] as tmv ON txn.Version_ID = tmv.ID
    WHERE tmv.Model_ID= @Model_ID AND txn.LastChgDTM <= @CleanupOlderThanDate
    EXEC sp_executesql @SQL, N'@Model_ID INT, @CleanupOlderThanDate DATE', @Model_ID, @CleanupOlderThanDate;
    --Delete all transactions older than the specified date
    SET @SQL = N'
    DELETE [mdm].' + QUOTENAME(@TransactionTableName) + N'
    FROM [mdm].' + QUOTENAME(@TransactionTableName) + N' txn
    JOIN [mdm].[tblModelVersion] tmv ON (txn.Version_ID = tmv.ID)
    WHERE tmv.Model_ID = @Model_ID AND txn.LastChgDTM <= @CleanupOlderThanDate
    EXEC sp_executesql @SQL, N'@Model_ID INT, @CleanupOlderThanDate DATE', @Model_ID, @CleanupOlderThanDate;
    RETURN(0);
    END TRY
    --Compensate as necessary
    BEGIN CATCH
    -- Get error info
    DECLARE
    @ErrorMessage NVARCHAR(4000),
    @ErrorSeverity INT,
    @ErrorState INT;
    EXEC mdm.udpGetErrorInfo
    @ErrorMessage = @ErrorMessage OUTPUT,
    @ErrorSeverity = @ErrorSeverity OUTPUT,
    @ErrorState = @ErrorState OUTPUT;
    RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState);
    --On error, return NULL results
    --SELECT @Return_ID = NULL;
    RETURN(1);
    END CATCH;
    SET NOCOUNT OFF
    END --proc
    GO

  • EJB3: What is the easiest way to handle the rapid change DB structure?

    Hi,
    I'm new in EJB, and it's the biggest leap to learn EJB3 without having strong fundamental in EJB 2.Currently, I'm facing the inefficient way to handle database rapid change on my Web Application. I choose JSP, Struts, and EJB3 with Oracle Database 10.1.0.5, Oracle Application Server 10.1.3.1, Oracle JDeveloper 10.1.3.2.
    I've followed tutorial how to make EJB3 Entity Bean, and how to access EJB Session Bean from JSP. But in that tutorial, there is no clue how to manage or change Entity Bean if there is a change in table structure, let say add 2 new fields, and change 1 field type from VARCHAR to NUMBER..
    What has been done was I create a new EJB3 project, and build all new Entity Bean. All generated JAVA file is copied and pasted to my current Entity Bean file.
    Is there any other easiest and simplest way to handle the rapid change in development process? As I noticed that EJB 3 using TopLink to handle Entity Bean creation process, but i haven't found articles or tutorial how to deal with my problem.
    Thanks..

    Unfortunately there is no automatic way to do this with EJB right now. You'll basically need to go into your entity bean and add/change the attribute to match the new database column.
    Note that we do provide automatic synchronization or the ADF Business Components framework - in case you choose to use it instead of EJB 3.0.
    Also if you are just starting your development/learning I think you might want to use JSF and not Struts. Seems like JSF has a much better future then Struts.

  • Is there a way to untag the tagged object?

    Is there a way to untag the tagged object in JVMTI ?
    Thanks, David

    In the "Object Tags" subsection of the "Heap" section in the JVM/TI spec:
    Setting a tag to zero makes the object untagged.

  • Correct way to call the character "&"

    I'm just full of questions today...
    I have a logo image called
    B&JBicycleBox_Resized_203x70.jpg  (Note the "&" character - that's where my question is coming from...)
    DW puts this as the HTML to reach it:
    <a target="_blank" href="
    http://bandjbicycle.com/ "><img alt="" width="190" height="70" src="images/sponsors/B&amp;JBicycleBox_Resized_203x70.jpg" /></a>
    (Yes, I realize the forward slashes are facing the wrong direction in the file name string...)
    And, DW also calls this a "Broken Link" ostensibly because the file ref is calling it:
    B&amp;JBicycleBox_Resized_203x70.jpg      I believe the &amp; is making it miss.
    Is it complaining because of the forward slashes and it can't find it?  Not surprisingly, it does play correctly in the browser.
    Or is there a correct way to layout the character of "&" that I'm just not finding.
    Hoibie.

    Absolutely!!!
    Perfect, Hans.  I owe you a Warsteiner....
    H

  • Correct Way to Obtain The Most Negative Double

    Is this the correct way to obtain the most negative double in Java?
    double v = -Double.MAX_VALUE;As Max positive byte is 127, but Max negative byte is -128, not -127
            byte c = 127;
            byte nc = (byte)(c + 1);
            if (nc > c) {
                System.out.println("+ve");
            else {
                // Come here.
                System.out.println("-ve");
            }However, how about double
    double v =Double.MAX_VALUE + 1;
    Is this makes sense? As, 1 is not the smallest increment unit for double.

    yccheok wrote:
    Is this the correct way to obtain the most negative double in Java?
    double v = -Double.MAX_VALUE;
    Double.MIN_VALUE;
    However, how about double
    double v =Double.MAX_VALUE + 1;
    Is this makes sense? As, 1 is not the smallest increment unit for double.No, 1 is not the smallest unit to increment a double with, the smallest unit of course would be negative infinity. Remember double has a fixed precision, so even if negative infinity existed, it would not be accurately represented by a double.
    Mel

  • Is there any way to handle the navigation without defining it in faces-conf

    hi,
    I am new to JSF and I got lots of information from this forum. My new query is given below,
    Is there any way to handle the navigation without defining it in faces-config.xml file? That means i want to navigate to a destination page programatically from the java class rather than declaring it it faces-config.xml file.
    Your help and suggestions are hightly appreciated...
    Thanks and regards,
    Sudheesh K S

    JSF as defaault looks your *-config.xml files in your web.xml configuration or default faces-config.xml file. If do not use default look third party tools like seam or others....                                                                                                                                                                                                                                                                                                                                                                   

  • Is there a way to download the update from OS X Leopard 10.5.8 to OS X Snow Leopard or do I need an install disc?

    I am trying to upgrade to Snow Leopard but I cannot figure out how to do it online. Do I actually need to purchase the disc and install it that way? Is there no way to download the update?

    LisaK78 wrote:
    I am trying to upgrade to Snow Leopard but I cannot figure out how to do it online. Do I actually need to purchase the disc and install it that way? Is there no way to download the update?
    See:
    Software update, upgrade--what's the difference?
    http://support.apple.com/kb/HT1444

  • Im trying to download the Io6 update but my connection is too slow and the update is too big is there another way to download the update?

    Im trying to download the Io6 update but my connection is too slow and the update is too big is there another way to download the update? Any ideas or help and what can i do? The update starts again if it is paused

    Use your friend's internet to update.

  • What's the correct way to handle changes in RDBMS/DBadapter?

    In my project all changes to the database are not done via Jdeveloper but via TOAD. This means DBadapters must be made aware of changes in the database.
    I tried to re-run the DBad.apter wizard twice (2 different services) - to make it aware of changes in the DB. Both times it failed. I think was after the import database tab. The next tab was just blank.
    So what's the correct way of reconile changes in the db backwards into Jdev?
    BTW, in the DBadapter wiz its not possible the remove a already imported table. How do I come across the situation where I want the DBadapter to point to af different table? - and possibly remove old references to another one - which might have been removed in the DB.
    As It is now - I have to re-work all my DBadapters, which is not very much fun...
    Rgds, Henrik

    Trust me, I hv done that umpteen nbr of times.
    I hate BA's coming to me with changes, for which I hv to modify the DB adapter.
    One big loop-hole with BPEL is if we try to modify the adapters/toplink, it doesnt tend to work properly.
    The manthra for such modifications is ... "recreate", which is definetely not a good practise.
    You may not like but gottu live with it, my friend.
    Pointing to a different table, I achieve it by doing a "Shift+Delete" to all the references of the old table in the BPEL project ... :|
    There isnt a specific provision in the wzd (I am not sure of the latest version, though).

  • Different ways to compare the java objects

    Hi,
    I want to compare rather search one object in collection of thousands of objects.
    And now i am using the method which uses the unique id's of objects to compare. still that is too much time consuming operation in java.
    so i want the better way to compare the objects giving me the high performance.

    If you actually tried using a HashMap, and (if necessary) if you correctly implemented certain important methods in your class (this probably wasn't necessary but might have been), and if you used HashMap in a sane way and not an insane way, then you should be getting very fast search times.
    So I conclude that one of the following is true:
    1) you really didn't try using HashMap.
    2) you tried using hashmap, but did so incorrectly (although it's actually pretty simple...)
    3) your searches are pretty fast, and any sluggishness you're seeing is caused by something else.
    4) your code isn't actually all that sluggish, but you assume it must be for some reason.
    Message was edited by:
    paulcw

  • Wich is correct way to handle Workflow of documents ?

    We are starting a project to handle Workflow of documents.
    We have an Enterprise with some Users that edit and publish documents;
    and related subcompanies that have Users that read only the documents.
    We have to handle the revisions of documents, the process phases and the validation
    of a revisor for each phase and also control the document access.
    Our backend database is Oracle 8 for Wordgroup (in the Enterprise) and IIS for the client access (from subcompanies).
    We want to use this architecture : client (HTML) and server (servlet, JSP).
    These documents are written with Word97 and are stored in Oracle 8.
    We plan in the future on updating Oracle 8 FWG > Oracle8 Enterprise > Oracle8i and the migration from IIS (NT Web Server) to (UNIX Solaris).
    My questions are:
    1) How control the open and save of documents with Oracle connection ?
    2) Is better to store the documents inside Oracle or just insert the URL in tables ?
    3) If I want to use ConText cartridge for searching mechanism where I have to store
    this documents ?
    4) For the servlets I need an Application Server ? Wich release ?
    Could you help me to get the correct solution. I would appreciate any suggestions.
    Thanks
    Lorenzo Baldovini.
    [email protected]

    Hi,
    You really need to take a look at the XMLDB Developers guide.
    For updating XML with SQL/XML see UPDATEXML and for XQuery see [Using XQuery with Oracle XMLDB|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb_xquery.htm#sthref1673]
    HTH,
    Chris

Maybe you are looking for

  • How to Migrate SSIS packages from 32 bit to 64 bit environment

    Hi, We developed many SSIS packages in 32 bit environment using SQL 2008 on windows 2003 server 32 bit OS. In order to utilize the 64 bit features we wish to migrate these packages into a 64 bit. Wanted to know. 1. Whether we can execute these packag

  • Import .swf not working

    I need to convert some swf files to .flv.  I know there are converters out there that do this, but I don't currently have any so if I can do it with PremE 8 I'd like to.  I read that .swf can be imported into Premiere, but when I import these particu

  • Debugging stored procedure in SQL Server 2012

    Hi, Please I need your help. I used to debug stored procedures in SQL server 2008, 2008 R2. I'm debugging the stored procedure using SQL Server management studio. I just create a break point then I click on the debug button and start debugging withou

  • Active Run Content

    hello, i've got a flash file (SWF). I have the file running on my production server. However, i've been using DW CS3 to create a new page to hold the SWF file. The page runs great when I display it under my local server. However, when I upload my DW-

  • Table size wrong in interent explorer- Nate Miller

    When I preview my site, www.el-ojito.com, my tables and content are fine in every browser except internet explorer. I used the same techniques to apply the background image for the page title in every page. However some pages, like accommodations, do