Why this Java Thread program doesn't work as expected?

Hello all:
I have a java code as follows:
My question is why tryThreadB which is set as deamon thread still run
after the main program return?
the output of this program looks like:
HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn Ending main()
HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn
However, I think the correct output should be:
HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn Ending main()
Hopalong Hopalong Hopalong Hopalong Hopalong Hopalong Hopalong Hopalong
====================================
<pre>
import java.io.*;
public class TryThread extends Thread {
private String firstName;
public TryThread(String firstName) {
this.firstName = firstName;
public static void main(String[] args) {
TryThread tryThreadA = new TryThread("Hopalong");
TryThread tryThreadB = new TryThread("Marilyn ");
// user thread
tryThreadA.setDaemon(false);
// daemon thread
tryThreadB.setDaemon(true);
tryThreadA.start();
tryThreadB.start();
try {
sleep(5000);
catch (InterruptedException ex) {
System.out.println("Ending main()");
return;
public void run() {
try {
while(true) {
System.out.print(firstName);
sleep(1000);
catch (InterruptedException ex) {
System.out.println(ex);
</pre>
====================================
thank you very much

Hi,
From the Thread documentation:
When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls
the method named main of some designated class). The Java Virtual Machine continues to execute
threads until either of the following occurs:
    * The exit method of class Runtime has been called and the security manager has permitted the exit
operation to take place.
    * All threads that are not daemon threads have died, either by returning from the call to the run method
or by throwing an exception that propagates beyond the run method.A daemon thread will not stop after the main method returns. It will stop when there are only daemon threads executing.
So, in your case, thread B will continue to execute as long as thread A (or any other non-daemon thread) is alive.
/Kaj

Similar Messages

  • Why tethering with USB cable doesn't work after IOS6.0 update?

    why tethering with USB cable doesn't work after IOS 6.0 update?

    Try updating the carrier settings, if that doesn't do it try following along with this Apple doc -> iOS: Troubleshooting Personal Hotspot

  • Why some eMac DVD SuperDrive doesn't work?

    Why some eMac DVD SuperDrive doesn't work?
    They have a limited hours life, or some DVD or CD can damage them?
    Thank you

    Hopefully some day I will find the answer for this question.

  • SAPGUI login scripting program doesn't work.

    I used a program which is called for sap login through local SAPGUI.
    I call this program, then sapgui is called and then ID and PW is filled with existing value.
    It worked well. however, we upgrade SAP frrom R/3 4.7 to ECC 6.0 and SAPGUI version is also changed.
    after uprading, my program doesn't work.
    although sapgui version is changed, my program can login R/3 4.7 server. but my program can't login ECC 6.0 server.
    In case of ECC 6.0 server, my program can call SAPGUI. however, it can't fill the ID and PW. so it cant login.
    I can't get the source of my program because I received only execution file.
    Can you suggest any solution? such as, change the dll file.
    Plz give me the solution!!!.

    Dear J-Philippe,
    I'm just getting started with SAP GUI Scripting through the COM interface and I seem to be running into the same issue.
    You seem to be referring to a work-around mentioned in the README (#4). I don't know where the README is located, could you (or somebody else) please post the work-around or the README or location thereof?
    By the way, here's the code I'm running (it's Python):
    import win32com.client
    wrapper = win32com.client.Dispatch("SapROTWr.SapROTWrapper")
    sap_gui = wrapper.GetROTEntry("SAPGUI")
    application = sap_gui.GetScriptingEngine
    connection = application.FindById("con[0]") # returns /app/con[0]
    session = connection.FindById("ses[0]") # throws exception
    The last statement fails with an exception "The control could not be found by id".
    When I use connection.Children(0) instead I get the exception "The enumerator of the collection cannot find an element with the specified index"
    Same results when using SapGui.ScriptingCtrl.1.
    Thanks!
    Edited by: brucevdk on Jan 31, 2011 7:51 PM
    I found the mentioned SAP note 1526624 somewhere (I don't yet have access to the official resource) and it made me think that perhaps I'm not dealing with the same issue. I'm also not sure what CreateObject is and if it's similar to the Dispatch functionality above (I'm just getting started with COM Programming). I'll play around with the recorder at work tomorrow to see if scripting works at all.

  • Paul Hyde's Java Thread Programming

    I have Paul Hyde's Java Thread Programming and I am wondering if it is a comprehensive book for learning the nuts n bolts of threads. I know how to use threads however I want to learn the inner details. Doug Lea's book is perhaps a better option but Paul Hyde's book seems more readiable.
    Any comments are appreciated.
    cheers

    Sounded interesting, found this link
    http://www.javaspecialists.co.za/archive/Issue056.html

  • Hello. I recently updated numbers on my macbook pro. I like the auto completion feature (proposing te word as I type). With this new update, I cannot see this feature and it doesn't work automatically. Can I have any help on this issue ?

    Hello. I recently updated numbers on my macbook pro. I like the auto completion feature (proposing te word as I type). With this new update, I cannot see this feature and it doesn't work automatically. Can I have any help on this issue ?

    This is really unfortunate. I'm sorry that nothing works. I was going to mention holding down the power button and doing a force shutdown but you already did that. You might need to take it into the Apple store. I don't know if booting into safe mode would help. You would have to turn off the machine again, hit the start button and hold down the shift key after you hear the tone, but normally you would let go of the shift key when you see the apple logo and spining wheel. Maybe by holding down the shift key after you here the tone will cause the screen to come back on? The other option is to start up from the 'install disk' if your machine came with one. You would insert the disk, then shut down the computer, and hold down the C key right after hitting the start button.
    Here's the link for the safeboot
    http://support.apple.com/kb/HT1564?viewlocale=nl_nl

  • Why an automatic sign in doesn´t work?

    Why an automatic sign-in doesn´t work? I have chosen to the choose: "Sign in me automatically when Skype starting".

    Hi Nadia,
    Although a slightly different issue, could you try solutions 1 and 2 from here: http://helpx.adobe.com/creative-cloud/kb/creative-cloud-application-recognizing-available. html
    Thanks,
    - Dave

  • ArrayDeque as a stack doesn't work as expected with complex objects

    Trying to use ArrayDeque as a strorage for complex values <PSList<PSol>> (i.e. Arraylists of structured Values PSol), this doesn't work as expected. The code below should produce different values of pSLWk, being stored on bkStack, which are then to be retrieved by pop() to the variables pSL1, pSL2, pSL3.
    However, retrieval only ends up with three identical data sets (variables) pS1,pS2, pS3.
            public PSList<PSol> pSL;
            private ArrayDeque<PSList<PSol>> bkStack=new ArrayDeque<PSList<PSol>>();
            pSLWk=new PSList<PSol>();       // Constructor copies some Array (static field) to the PSLists
            pSL=new PSList<PSol>();
            pSLAux=new PSList<PSol>(pSLWk);   // Constructor copies from existing PSList
            pSLWk.checkResult("pSLWk prior to setDefaults - modifies pSLWk !");
            setDefaults();                                                            // Modifies pSLWk only
            pSLWk.checkResult(" pSLWk after setDefaults");              // .. got changes (o.k.)
            pSL.checkResult(" pSL after setDefaults");                  // .. unchanged  (o.k.)
            pSL.checkResult(" pSLAux after setDefaults");               // .. unchanged  (o.k.)
            bkStack.push(new PSList<PSol>(pSLWk));                      // store changes in bkStack
            pSLWk.getEl(77).setVal(new StringBuffer("4"));              // change pSLWk again (value 4 @ 77)
            pSLWk.checkResult("pSLWk, after PUSH, THEN modify 4@77");   // .. got change (o.k.)
            pSL.checkResult("pSL after setVal 77");
            bkStack.push(pSLWk);                      // store changes in bkStack
            pSLWk.getEl(80).setVal(new StringBuffer("8"));              // change pSLWk again (value 8 @ 80)
            pSLWk.checkResult("pSLWk after setVal 8@80");               // .. got change (o.k.)
            pSL.checkResult("pSL after setVal 80");
            bkStack.push(new PSList<PSol>(pSLWk));                      // store changes in bkStack
            pSL1=new PSList<PSol>(bkStack.pop());
            pSL1.checkResult("pSL1 after 1st pop");
    //      pSL1=bkStack.pop()                                          // Straightforward way doesn't work either...
            pSL2=new PSList<PSol>(bkStack.pop());
            pSL2.checkResult("pSL2 after 2nd pop");
            pSL3=new PSList<PSol>(bkStack.pop());
            pSL3.checkResult("pSL3 after 3rd pSLWk=..pop()");Here the result from the code above:
    debug:
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.>pSLWk prior to setDefaults - modifies pSLWk !
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2   63 <C.R.> pSLWk after setDefaults
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.> pSL after setDefaults
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.> pSLAux after setDefaults
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  463 <C.R.>pSLWk, after PUSH, THEN modify 4@77
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.>pSL after setVal 77
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSLWk after setVal 8@80
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.>pSL after setVal 80
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSL1 after 1st pop
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSL2 after 2nd pop
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSL3 after 3rd pSLWk=..pop()
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.>pSLWk prior to setDefaults - modifies pSLWk !
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2   63 <C.R.> pSLWk after setDefaults
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.> pSL after setDefaults
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.> pSLAux after setDefaults
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  463 <C.R.>pSLWk, after PUSH, THEN modify 4@77
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.>pSL after setVal 77
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSLWk after setVal 8@80
    1 8 9   4  5 42 9 7  5  2 6 4 923     1  7   3         86   7 5  3 69     2   63 <C.R.>pSL after setVal 80
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSL1 after 1st pop
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSL2 after 2nd pop
    128 96  4635 42 9 7945  2 6 47923     1  7   3 9       86   7 5  3 69     2  4638<C.R.>pSL3 after 3rd pSLWk=..pop()What's the problem with this ?
    Rem: I tried the simple approach as well:
    bkstack.push(pSLWk);
    ...

    Thank you for your comments, although I see we still don't have a common understanding of the problem.
    Firstly, I add the code for the PSList and the PSol classes, so you might find some problem with that:
         public class PSol     {
              private StringBuffer val;
              private int zI;
              private int sI;
              private int bI;
                        // == Konstruktor
              public PSol( StringBuffer v, int z, int s, int b )     {
                   this.val=v;
                   this.zI=z;
                   this.sI=s;
                   this.bI=b;
                        // == Getter,Setter
              public StringBuffer getVal()     {return val;}
              public int getZ()     {return zI;}
              public int getS()     {return sI;}
              public int getB()     {return bI;}
              public int getVSize()     {return val.length();}
              public void setVal(StringBuffer v)     {val=v;}
              public boolean hasVChar( StringBuffer ch, boolean delCh )     {
                   boolean bT=false;
                   StringBuffer fSt=getVal();
                   if (!(fSt.indexOf( ch.toString() )     == -1))     {
                        bT=true;
                        if (delCh)     {
                             setVal(fSt.deleteCharAt(fSt.indexOf( ch.toString() )));
                   return bT;
         }     // PSol
         public class PSList<E> extends ArrayList<PSol>     {
                   /**     Construktor 1: PSList(v,z,s,b) - makes list from single arrays
              private static final long serialVersionUID =  4711L;                         // ### JAVAC Warning! ###
            public PSList (String[] vS, int[] z, int[] s, int[] b) {
                   StringBuffer[] v=new StringBuffer[valDim];
                for (int i=0;i<valDim;i++)  {
                    v=new StringBuffer(vS[i]);
    //ArrayList<PSol> pSL=new ArrayList<PSol>;
                   for (int i=0; i<valDim; i++) {
                        this.add( new PSol( v[i], z[i], s[i], b[i] ) );
    /** Konstruktor2 : makes list from matrix array
    public PSList () {
    for (int j=0; j<nDim; j++) {
    for (int i=0; i<nDim; i++) {
    this.add( new PSol( new StringBuffer(sGuiArr[i][j]), i, j , i/locDim + (j/locDim)*locDim) );
                        /**     ------- Construktor 3 : PSList(PSList pS) - makes list as a copy of an existing one
    public PSList ( PSList<PSol> pX )     {
                   super (pX); // ArrayList-Constructor (Collection)
    // get Element <PSol>
    public PSol getEl ( int i )     {return get(i);}
         public int getCount()     {return size();}
         public int getTValLg()     {
                   int lg=0;
                   for (int i=0; i<getCount(); i++)     {
                        lg=lg + getEl(i).getVal().length();
                   return lg;
                        /**     ------- checkResult()     -     Check if alll elements are single char +dump
         public boolean checkResult(String messg)     {
                   boolean allOne=true;
                   for (int i=0; i<size(); i++)     {
                        if ( getEl(i).getVal().length() > 1 )     {
                             allOne=false;
                             System.out.print(" ");
                   else     {
                        System.out.print(getEl(i).getVal());
                   System.out.println("<C.R.>"+messg);
                   return allOne;
         }     // Class PSList
    Secondly, I don't really see what you mean by pointing out to 'only one "pSLWk" instance of PSList'. The variable pSLWk is the variable to be worked upon; after some change of the contents, I want to save this state of contents to the stack. When I pop that variable from the stack, I wouldn't want to restore it to pSLWK, but to some other variable, e.g. by public PSList<PSol> pSL1;
    pSL1=new PSList<PSol>(bkStack.pop());Again - to my understanding (which comes from old days of microprocessor coding... - there shouldn't be a need to know how the data came there, or what was the name of the variable who stored it there. And  : the implementation of ArrayDeque returns 'elements' of class E, not references !
    Thirdly, you're right, that the method of using a copy constructor for retrieval looks 'weird'. However - I had some other versions that didn't work either, e.g. the straightforward one, as I pointed out.
    And fourthly: yes, I'm almost sure that I'm messing up something somewhere. I went to this forum hoping to clarify that ... :)
    If you don't mind, could you please sketch a few lines of code, how to 'push' a complex variable to a ArrayDeque stack, and retrieve it - by 'pop()' - to some to other variable of the same class later ?
    Might make our discussion much easier, to see how things REALLY work.
    Thank you !                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • VoiceOver navigation buttons doesn't work as expected on latest version of Firefox

    VoiceOver navigation buttons doesn't work as expected on latest version of Firefox. VO+Left/Right not jump from element to element
    Version of OS: OS X Yosemite 10.10.1
    Version of Chrome: 42.0.2311.90 (64-bit)
    Version of Firefox: 37.0.2

    Did this work in a previous version of Firefox?
    There is an open bug to improve accessibility on OS X. (Bug 336306) I'll update that bug with any relevant information you provide here.

  • Why this Query is taking much longer time than expected?

    Hi,
    I need experts support on the below mentioned issue:
    Why this Query is taking much longer time than expected? Sometimes I am getting connection timeout error. Is there any better way to achieve result in shortest time.  Below, please find the DDL & DML:
    DDL
    BHDCollections
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[BHDCollections](
     [BHDCollectionid] [bigint] IDENTITY(1,1) NOT NULL,
     [GroupMemberid] [int] NOT NULL,
     [BHDDate] [datetime] NOT NULL,
     [BHDShift] [varchar](10) NULL,
     [SlipValue] [decimal](18, 3) NOT NULL,
     [ProcessedValue] [decimal](18, 3) NOT NULL,
     [BHDRemarks] [varchar](500) NULL,
     [Createdby] [varchar](50) NULL,
     [Createdon] [datetime] NULL,
     CONSTRAINT [PK_BHDCollections] PRIMARY KEY CLUSTERED
     [BHDCollectionid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    BHDCollectionsDet
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[BHDCollectionsDet](
     [CollectionDetailid] [bigint] IDENTITY(1,1) NOT NULL,
     [BHDCollectionid] [bigint] NOT NULL,
     [Currencyid] [int] NOT NULL,
     [Denomination] [decimal](18, 3) NOT NULL,
     [Quantity] [int] NOT NULL,
     CONSTRAINT [PK_BHDCollectionsDet] PRIMARY KEY CLUSTERED
     [CollectionDetailid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    Banks
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Banks](
     [Bankid] [int] IDENTITY(1,1) NOT NULL,
     [Bankname] [varchar](50) NOT NULL,
     [Bankabbr] [varchar](50) NULL,
     [BankContact] [varchar](50) NULL,
     [BankTel] [varchar](25) NULL,
     [BankFax] [varchar](25) NULL,
     [BankEmail] [varchar](50) NULL,
     [BankActive] [bit] NULL,
     [Createdby] [varchar](50) NULL,
     [Createdon] [datetime] NULL,
     CONSTRAINT [PK_Banks] PRIMARY KEY CLUSTERED
     [Bankid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    Groupmembers
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[GroupMembers](
     [GroupMemberid] [int] IDENTITY(1,1) NOT NULL,
     [Groupid] [int] NOT NULL,
     [BAID] [int] NOT NULL,
     [Createdby] [varchar](50) NULL,
     [Createdon] [datetime] NULL,
     CONSTRAINT [PK_GroupMembers] PRIMARY KEY CLUSTERED
     [GroupMemberid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    ALTER TABLE [dbo].[GroupMembers]  WITH CHECK ADD  CONSTRAINT [FK_GroupMembers_BankAccounts] FOREIGN KEY([BAID])
    REFERENCES [dbo].[BankAccounts] ([BAID])
    GO
    ALTER TABLE [dbo].[GroupMembers] CHECK CONSTRAINT [FK_GroupMembers_BankAccounts]
    GO
    ALTER TABLE [dbo].[GroupMembers]  WITH CHECK ADD  CONSTRAINT [FK_GroupMembers_Groups] FOREIGN KEY([Groupid])
    REFERENCES [dbo].[Groups] ([Groupid])
    GO
    ALTER TABLE [dbo].[GroupMembers] CHECK CONSTRAINT [FK_GroupMembers_Groups]
    BankAccounts
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[BankAccounts](
     [BAID] [int] IDENTITY(1,1) NOT NULL,
     [CustomerID] [int] NOT NULL,
     [Locationid] [varchar](25) NOT NULL,
     [Bankid] [int] NOT NULL,
     [BankAccountNo] [varchar](50) NOT NULL,
     CONSTRAINT [PK_BankAccounts] PRIMARY KEY CLUSTERED
     [BAID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    ALTER TABLE [dbo].[BankAccounts]  WITH CHECK ADD  CONSTRAINT [FK_BankAccounts_Banks] FOREIGN KEY([Bankid])
    REFERENCES [dbo].[Banks] ([Bankid])
    GO
    ALTER TABLE [dbo].[BankAccounts] CHECK CONSTRAINT [FK_BankAccounts_Banks]
    GO
    ALTER TABLE [dbo].[BankAccounts]  WITH CHECK ADD  CONSTRAINT [FK_BankAccounts_Locations1] FOREIGN KEY([Locationid])
    REFERENCES [dbo].[Locations] ([Locationid])
    GO
    ALTER TABLE [dbo].[BankAccounts] CHECK CONSTRAINT [FK_BankAccounts_Locations1]
    Currency
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[Currency](
     [Currencyid] [int] IDENTITY(1,1) NOT NULL,
     [CurrencyISOCode] [varchar](20) NOT NULL,
     [CurrencyCountry] [varchar](50) NULL,
     [Currency] [varchar](50) NULL,
     CONSTRAINT [PK_Currency] PRIMARY KEY CLUSTERED
     [Currencyid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    CurrencyDetails
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING ON
    GO
    CREATE TABLE [dbo].[CurrencyDetails](
     [CurDenid] [int] IDENTITY(1,1) NOT NULL,
     [Currencyid] [int] NOT NULL,
     [Denomination] [decimal](15, 3) NOT NULL,
     [DenominationType] [varchar](25) NOT NULL,
     CONSTRAINT [PK_CurrencyDetails] PRIMARY KEY CLUSTERED
     [CurDenid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    QUERY
    WITH TEMP_TABLE AS
    SELECT     0 AS COINS, BHDCollectionsDet.Quantity AS BN, BHDCollections.BHDDate AS CollectionDate, BHDCollectionsDet.Currencyid,
                          (BHDCollections.BHDCollectionid) AS DSLIPS, Banks.Bankname
    FROM         BHDCollections INNER JOIN
                          BHDCollectionsDet ON BHDCollections.BHDCollectionid = BHDCollectionsDet.BHDCollectionid INNER JOIN
                          GroupMembers ON BHDCollections.GroupMemberid = GroupMembers.GroupMemberid INNER JOIN
                          BankAccounts ON GroupMembers.BAID = BankAccounts.BAID INNER JOIN
                          Currency ON BHDCollectionsDet.Currencyid = Currency.Currencyid INNER JOIN
                          CurrencyDetails ON Currency.Currencyid = CurrencyDetails.Currencyid INNER JOIN
                          Banks ON BankAccounts.Bankid = Banks.Bankid
    GROUP BY BHDCollectionsDet.Quantity, BHDCollections.BHDDate, BankAccounts.Bankid, BHDCollectionsDet.Currencyid, CurrencyDetails.DenominationType,
                          CurrencyDetails.Denomination, BHDCollectionsDet.Denomination, Banks.Bankname,BHDCollections.BHDCollectionid
    HAVING      (BHDCollections.BHDDate BETWEEN @FromDate AND @ToDate) AND (BankAccounts.Bankid = @Bankid) AND (CurrencyDetails.DenominationType = 'Currency') AND
                          (CurrencyDetails.Denomination = BHDCollectionsDet.Denomination)
    UNION ALL
    SELECT     BHDCollectionsDet.Quantity AS COINS, 0 AS BN, BHDCollections.BHDDate AS CollectionDate, BHDCollectionsDet.Currencyid,
                          (BHDCollections.BHDCollectionid) AS DSLIPS, Banks.Bankname
    FROM         BHDCollections INNER JOIN
                          BHDCollectionsDet ON BHDCollections.BHDCollectionid = BHDCollectionsDet.BHDCollectionid INNER JOIN
                          GroupMembers ON BHDCollections.GroupMemberid = GroupMembers.GroupMemberid INNER JOIN
                          BankAccounts ON GroupMembers.BAID = BankAccounts.BAID INNER JOIN
                          Currency ON BHDCollectionsDet.Currencyid = Currency.Currencyid INNER JOIN
                          CurrencyDetails ON Currency.Currencyid = CurrencyDetails.Currencyid INNER JOIN
                          Banks ON BankAccounts.Bankid = Banks.Bankid
    GROUP BY BHDCollectionsDet.Quantity, BHDCollections.BHDDate, BankAccounts.Bankid, BHDCollectionsDet.Currencyid, CurrencyDetails.DenominationType,
                          CurrencyDetails.Denomination, BHDCollectionsDet.Denomination, Banks.Bankname,BHDCollections.BHDCollectionid
    HAVING      (BHDCollections.BHDDate BETWEEN @FromDate AND @ToDate) AND (BankAccounts.Bankid = @Bankid) AND (CurrencyDetails.DenominationType = 'COIN') AND
                          (CurrencyDetails.Denomination = BHDCollectionsDet.Denomination)),
    TEMP_TABLE2 AS
    SELECT CollectionDate,Bankname,DSLIPS AS DSLIPS,SUM(BN) AS BN,SUM(COINS)AS COINS  FROM TEMP_TABLE Group By CollectionDate,DSLIPS,Bankname
    SELECT CollectionDate,Bankname,count(DSLIPS) AS DSLIPS,sum(BN) AS BN,sum(COINS) AS coins FROM TEMP_TABLE2 Group By CollectionDate,Bankname
    HAVING COUNT(DSLIPS)<>0;

    Without seeing an execution plan of the query it is hard to suggest something useful. Try insert the result of UNION ALL to the temporary table and then perform an aggregation on that table, not a CTE.
    Just
    SELECT CollectionDate,Bankname,DSLIPS AS DSLIPS,SUM(BN) AS BN,SUM(COINS)AS COINS  FROM
    #tmp Group By CollectionDate,DSLIPS,Bankname
    HAVING COUNT(DSLIPS)<>0;
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • What to do when your program doesn't work.

    A huge number of posts here seem to relate to code that has been written (one presumes by the poster), but which doesn't work.
    I get the impression that people don't know what to do next.
    It's really not that difficult. When you're writing your program you constantly have in mind what you expect will happen as a result of each bit of code that you put.
    If at the end of the day, the program as a whole doesn't behave as you expected, then somewhere in there there must be a point at which the program starts doing something that doesn't correspond to what you anticipated. So, you add some System.err.println statements to test your beliefs.
    Consider this program that tests whether a number is prime.
    public class Test
        public static void main(String args[])
            // Get the number to test.
            int number = Integer.parseInt(args[0]);
            // Try each possible factor.
            int factor;
            for(factor = 2; factor < number; factor++)
                // See whether it is really a factor.
                if(number / factor == 0)
                    break;
            if(factor == number)
                System.out.println("Number is not prime.");
            else
                System.out.println("Number is prime.");
    }Straight forward enough, but it doesn't actually work :( It seems to say that every number is not prime. (Actually, not quite true, but I didn't test it that carefully, since it didn't work).
    Now, I could scrutinise it for errors, and then, having failed to find the problem, I could post it here. But let's suppose I'm too proud for that.
    What might be going wrong. Well, how sure am I that I'm even managing to capture the number of interest, number. Let's put in a System.err.println() to test that.
    Is the program in fact trying the factors I expect? Put in System.err.println() for that.
    Is the program correctly determining whether a number is a factor? Need another System.err.prinln (or two) for that.
    public class Test
        public static void main(String args[])
            // Get the number to test.
            int number = Integer.parseInt(args[0]);
            System.err.println("Number to check is " + number);
            // Try each possible factor.
            int factor;
            for(factor = 2; factor < number; factor++)
                System.err.println("Trying factor " + factor);
                // See whether it is really a factor.
                if(number / factor == 0)
                    System.err.println(factor + " is a factor.");
                    break;
                System.err.println(factor + " is not a factor.");
            if(factor == number)
                System.out.println("Number is not prime.");
            else
                System.out.println("Number is prime.");
    }Let's try with on the number 6.
    The output is:
    Number to check is 6
    Trying factor 2
    2 is not a factor.
    Trying factor 3
    3 is not a factor.
    Trying factor 4
    4 is not a factor.
    Trying factor 5
    5 is not a factor.
    Number is not prime.
    Whoah! That's not right. Clearly, the problem is that it's not correctly deciding whether a number is a factor. Well, we know exactly where that test is done. It's this statement:
                if(number / factor == 0)Hmm.... let's try 6 / 3, 'cos 3 is a factor.
    6 / 3 = 2.
    But that's not zero. What the.... Oh - I see, it should have been number % factor.
    Ok - let's fix that, and run it again.
    Now the output is:
    Number to check is 6
    Trying factor 2
    2 is a factor.
    Number is prime.
    Not the right answer, but at least it's now figured out that 2 is a factor of 6. Let's try a different number.
    Number to check is 9
    Trying factor 2
    2 is not a factor.
    Trying factor 3
    3 is a factor.
    Number is prime.
    Again, got the right factor, but still the wrong answer. Let's try a prime:
    Number to check is 7
    Trying factor 2
    2 is not a factor.
    Trying factor 3
    3 is not a factor.
    Trying factor 4
    4 is not a factor.
    Trying factor 5
    5 is not a factor.
    Trying factor 6
    6 is not a factor.
    Number is not prime.
    Aagh! Obvious - the final test is the wrong way round. Just fix that, remove that System.err.println()s and we're done.
    Sylvia.

    Consider this program that tests whether a number is
    prime.
    [attempt to divide by each integer from 2 to n-1]At risk of lowering the signal to noise ratio, I
    should point out that the algorithm given is just
    about the worst possible.
    I know that the point was to illustrate debugging
    and not good prime test algorithms, and I disagree
    with the correspondent who thought the post was
    condescending.
    Anyway, the java libraries have good prime testing
    methods based on advanced number theory research that the
    non-specialist is unlikely to know. Looking at the java
    libraries first is always a good idea.
    Even with the naive approach, dramatic improvements
    are possible.
    First, only try putative divisors up to the square root
    of the number. For 999997 this is about 1000 times faster.
    Next only try dividing by prime numbers. This is about
    7 times faster again. The snag, of course, is to find the
    prime numbers up to 1000, so there might not be much
    advantage unless you already have such a list. The sieve
    of Erastosthenes could be used. This involves 31 passes
    through an array of 1000 booleans and might allow an
    improvement in speed at the expense of space.
    Sorry if I've added too much noise :-)

  • SignalExpr​ess program doesn't work when reloaded

    I am new to SignalExpress and am trying to do a simple program in as a example to show a customer how to use a USB-6008 as a device to control and measure one of their devices.  I am using digital outputs and they work correctly when I first enter and run the program.  However if I exit and reload the same program, any "digital port output" blocks that precede a "Sequence" block fail to correctly output a "1".  My sequence blocks have "allow hardware reuse" checked (so I can flip the same bits in different parts of the program).
    I can tell when a "digital port output" block isn't going to work correctly by turning on the "preview" pane for it.  If the "Value to Write" box is "High" this pane should show a filled radio button.  This is set correctly when I first create the block.  But if I close SignalExpress and reload the program this radio button will not be filled, and the USB-6008 won't correctly set the output to a "1".
    If I manually set the output control to "0" and then back to "1", then the radio button will be filled again, and the program will work correctly again.
    At first glance this appears to be a bug.  Any help or suggestions appreciated.  A copy of the SignalExpress VI and screen snapshots is attached.  Thanks.
    Chuck
    When it works correctly (note radio button near top is filled):
    When it doesn't work correctly (note all setttings are the same but radio button near top is empty):
    This shows a snapshot of the Sequence block:
    Attachments:
    SignalExpress_Digital_Problem.zip ‏238 KB

    Thanks for looking at this.  Sorry about the duplicate post, but I realized I had put it in the wrong place and couldn't figure out how to delete it from the first string.
    I was using the Sequence blocks so that I could set a digital line high, wait for 30 ms, set it low, and then make an ADC measurement and a limit test.  Then if that passed other patterns would be generated.  When I tried to do this is seperate blocks I was told I couldn't use the same resource without using the Sequence block with resource sharing turned on.  That was why I added the Sequence block.
    Chuck

  • Program doesn't work correctly after a copypaste from a working program

    Hi everybody!
    i made a really easy program, that doesn't work for some mysterious reasons...
    This first one is the prototype of the program: http://pastebin.com/fpFy3uLn
    in this version all is working correctly!
    So, where is the problem?
    The problem is that, once i copy-pasted the functions in the main program, it stopped to work!
    I have no compilation error or similar...
    This is the final program, the one that doesn't work: http://pastebin.com/7EWn1VSF
    thx a lot for your attention

    I commented the whole
    #Section "InputDevice"
    #       Identifier  "Synaptics Touchpad"
    #EndSection
    part
    and the appropiate line
            #InputDevice "Synaptics Touchpad" "SendCoreEvents"
    on Sever Layout.
    It stopped the EE error, touchpad works here
    but it's reverted to old "typing=accidentally doing clicks" since it got way too sensitive
    I can't run gsynaptics , synclient or syndaemon to fix it (as I used to)
    since I get
    drini ~ $ synclient
    Couldn't find synaptics properties. No synaptics driver loaded?

  • Why custom logon error messages doesn't work in WAS 7.0, EP 7.0?

    I managed to get custom error messages in WAS 6.40 / EP 6.0.
    I'm using JAAS custom Login module for user authentication and from there different Login Exceptions are thrown.
    I have modified logon.par file to display different error messages like "Logon ID is empty", "Password is empty", "Your user ID or password could not be validated.  Please check and try again."
    When i copy the same code into my working environment i.e WAS 7.0 / EP 7.0, it doesn't work, message always was "User Authentication Failed". Do anyone knows the reason why i was like that?
    Can you please explain exactly when the custom login module gets executed after the user clicks on "Logon" Button.
    In logon.par file i have not seen any code to execute JAAS - custom logon module. PLease explain exact execution flow ..
    Thanks in advance ..
    MMK

    Your card reader might be finicky like mine. Figure out which device your card reader is at (from what I'm reading probably sdb), then attempt to mount /dev/sdb to any location. If your card reader is like mine, this mount will fail but you'll find you now magically have /dev/sdb1, /dev/sdb2, etc devices, which will successfully mount... oddness, but it "just works" so I'm happy
    Note that if you plug a card into a slot that is to the kernel, for example, /dev/sda2, then try to mount /dev/sda1, this will (obviously) fail, so be sure to try mounting all the devices that magically appear (if any do).
    -dav7

  • Question about java threads programming

    Hi
    I have to develop a program where I need to access data from database, but I need to it using multithreading, currently I go sequentially to each database to access data which is slow
    I have a Vector called systemnames, this one has list of all the systems I need to access.
    Here is my current code, some thing like this
    Vector masterVector = new Vector();
    GetData data = new GetData();
    For(int i =0; i < systemnames.size(); i++)
    masterVector.add(data.getData((String)systemnames.get(i));
    public class GetData
    private Vector getData(String ipaddress)
    //process SQL here
    return data;
    how do i convert this to multithread application, so there will be one thread running for each system in vector, this is speed up the process of extracting data and displaying it
    has any one done this kind of program, what are the precautions i need to take care of
    Ashish

    http://www.google.com/search?q=java+threads+tutorial&sourceid=opera&num=0&ie=utf-8&oe=utf-8
    http://java.sun.com/docs/books/tutorial/essential/threads/
    http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
    http://www.cs.clemson.edu/~cs428/resources/java/tutorial/JTThreads.html
    http://www-106.ibm.com/developerworks/edu/j-dw-javathread-i.html
    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read and prevents accidental markup from array indices like [i].

Maybe you are looking for

  • Mail attachement content trnsfer encoding 8bit , 7bit

    Good morning to everybody. I have a problem reading mail attachement. When the attachement is 8bit encoded the exadecimal char "3D" is write in a file as "0D". This is wrong When the attachement is 7bit encoded the exadecimal char "3D" is write in a

  • STOP is shown as obselete -- any alternate

    Hi all, I have STOP used in my code which is shown as an obsolete Error during Extended Syntax Check in ECC 6.0. Can any one tell me if we have an alternate. Surya Kiran.

  • Reset the company code before changing chart of accounts

    i have created a new chart of accounts. when i m trying to assign to company code i m getting this error. i tried with OBR1 tcode also but still getting the error. how to solve this issue.. thanks in advance.

  • Lost i-tunes lib.

    lost i-tunes library after downloading and installing latest version of i-tunes and quick-time. how does one go about restoring music library without reloading complete 16gb of data?

  • How is the ep openings now

    Hi Experts, how is the ep market? how is the ep openings? if u know any openings then please post me in this forum Regards, Chowdary.