Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro Java
Pro Java Expert level Java questions not about a specific book. Please indicate your version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 23rd, 2009, 09:11 PM
Authorized User
Join Date: Feb 2009
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to properly synchronize Threads/Classes

Hello All! Thank you very much for viewing this thread. My problem is I am trying to pass a number value between classes/thread of the same java project in eclipse. I have a java project of 9 classes with three threads. The Display Class/Thread needs to accept a value coming from the Tcpdump Class/Thread. When both of these are ran separately everything is fine. But when I try to pass the count value in Tcpdump it does not function correctly. I am trying to understand synchronizing since I think that is my solution however I do not really know where to begin. I have posted the Tcpdump class below.
import java.io.IOException;
import jpcap.*;
import jpcap.packet.Packet;

public class Tcpdump extends Thread implements PacketReceiver{

static int index = 1;
public int received_packets;
//int count = 0;
public int count;
public int packetPSecond;
private Main classMain;
public int tcpdumpSecondCount;
NetworkInterface[] devices = JpcapCaptor.getDeviceList();

public Tcpdump(Main projectMain){
this.classMain = projectMain;

public void receivePacket(Packet packet) {
System.out.println("THIS IS THE PACKET NUMBER: " + " - " + packet);

public void countPackets() {
this.count = this.count + 1;
System.out.println("This is the value of count: " + count);

//This line passes count--which is the (Total Number of packets)

public void openDevice() {
System.out.println("This is Tcpdump Opendeive...packets should be captured now");
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
JpcapCaptor jpcap = null;
System.out.println("usage: java Tcpdump <select a number from the following>");
try {
jpcap = JpcapCaptor.openDevice(devices[0], 2000, false, 1000);
//jpcap = JpcapCaptor.openDevice(devices[1], 2000, false, 1000);
} catch (IOException e) {


jpcap.loopPacket(-1, new Tcpdump(classMain));

public void run() {
System.out.println("Tcpdump is on--------------------------!!!");

public void main() throws Exception {
System.out.println("This is Tcpdump main, openDevice should start:");

__________________________________________________ __
The display method I am using to accept the value is

public void gettcpDumpPacketCount(int count){
System.out.println("THis is count at display: " + count);
dumpPacketCount = count;

__________________________________________________ __
Both classes and threads are initialized in my main class.

I would appreciate any advice you could give me. Thanks a lot.


Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronize combo box HDMorales Access VBA 2 February 8th, 2006 12:34 PM
sYNCHRONIZE COMMAND_CLICK EVENT Kaustav Pro VB 6 1 September 19th, 2005 01:12 PM
how to synchronize between two database zerra Java Databases 1 August 4th, 2005 12:09 AM
How to synchronize time on two computers Vladimirs VB How-To 0 June 29th, 2003 06:55 AM
Problems with threads. Threads disappearing? DriesNeyrinck VB.NET 0 June 10th, 2003 08:26 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.