Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 93444 invoked from network); 14 Aug 2009 00:46:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Aug 2009 00:46:53 -0000 Received: (qmail 10598 invoked by uid 500); 14 Aug 2009 00:46:57 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 10514 invoked by uid 500); 14 Aug 2009 00:46:57 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 10504 invoked by uid 99); 14 Aug 2009 00:46:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Aug 2009 00:46:57 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of glen.newton@gmail.com designates 209.85.132.241 as permitted sender) Received: from [209.85.132.241] (HELO an-out-0708.google.com) (209.85.132.241) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Aug 2009 00:46:47 +0000 Received: by an-out-0708.google.com with SMTP id b2so439077ana.5 for ; Thu, 13 Aug 2009 17:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=qVpTNJRrj00jtw40P1t7NBkQ+7jW6E4QTWVQEqTFyJk=; b=dDSWjXnjusyzkqEuJ2DDVUlxo6USCWmHNW1TE99owqzrUgGrqJ0HbCmD/+vl23uEqE rcFWcKPM+L/7+EluGt4vYwpJdAWp+CuOO38wRrIOTujxD4W610PAqTqdlvYQGZaDnaVW 1bxuYyuT1xjpJEPyMHuyiZ9m+sIauQLRrzD7I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=t6Hf3JgE7jNO3SbVdnw4LVtANUoAp7yB5rL+ETPULjWzUQ4TZAV4RzYbcd148XzNQs vfEQF3ThEKDcdILvkko5Ht7SgfM4SYYRizf6tlJqA2yw9lF2R7CHzpCHzNIgKvrhYYWG 5zXMt1gNy2gCW0ETs+I0ts+MqMNf53TYUo8A4= MIME-Version: 1.0 Received: by 10.100.51.10 with SMTP id y10mr1374088any.128.1250210786942; Thu, 13 Aug 2009 17:46:26 -0700 (PDT) In-Reply-To: <1c3e185f0908130353x1a354007o7c1cc77251e702b2@mail.gmail.com> References: <1c3e185f0908130353x1a354007o7c1cc77251e702b2@mail.gmail.com> Date: Thu, 13 Aug 2009 20:46:26 -0400 Message-ID: <5e76f3840908131746n5f32397ew720772f9c2ec72c@mail.gmail.com> Subject: Re: [EASY]How to change the demo of lucene143 into a multithread one? From: Glen Newton To: java-user@lucene.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org You are optimizing before the threads are finished adding to the index. I think this should work: IndexWriter writer =3D new IndexWriter("D:\\index", new StandardAnalyzer(), true); File file=3Dnew File(args[0]); Thread t1=3Dnew Thread(new IndexFiles(writer,file)); Thread t2=3Dnew Thread(new IndexFiles(writer,file)); Thread t3=3Dnew Thread(new IndexFiles(writer,file)); t1.start(); t2.start(); t3.start(); while(t1.getState()!=3DState.TERMINATED ||t2.getState()!=3DState.TERMINATED ||t3.getState()!=3DState.TERMINATED ){ try{ Thread.currentThread().sleep(100l); } catch(InterruptedException ie) { ie.printStackTrace(); } }//wait until the threads end. writer.optimize(); writer.close(); Date end =3D new Date(); 2009/8/13 Chuan SHI : > Hi all, > =C2=A0 =C2=A0 =C2=A0 I am new to multi-thread programming and lucene. I w= ant to change the > indexing demo of lucene143 into a multi-thread one. I create one instance= of > IndexWriter which is shared by three threads. But I find that the time it > costs when three threads are used is approximate three times of that of > single thread.(My computer is dual-core) It seems I write a pseudo > multi-thread program and it does the same work for three times. > Following is a snippet of my code. Please tell me how to write the correc= t > code. Thanks. > > IndexWriter writer =3D new IndexWriter("D:\\index", new StandardAnalyzer(= ), > true); > File file=3Dnew File(args[0]); > Thread t1=3Dnew Thread(new IndexFiles(writer,file)); > Thread t2=3Dnew Thread(new IndexFiles(writer,file)); > Thread t3=3Dnew Thread(new IndexFiles(writer,file)); > t1.start(); > t2.start(); > t3.start(); > writer.optimize(); > writer.close(); > > while(t1.getState()!=3DState.TERMINATED > ||t2.getState()!=3DState.TERMINATED > ||t3.getState()!=3DState.TERMINATED > ){}//wait until the threads end. > Date end =3D new Date(); > > -- > Best regards, > > Chuan SHI > --=20 - --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org