473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading. Is this an Issue?

Sup everyone!

I wrote this code for Tomcat appserver but I am told from an
associate that it has threading issues. The basic idea is to store a
read only data table for everyone to use. It takes some time for the
table to be created. I want to store the table in a singleton and
update it periodicly, basicaly when a user logs into the system. By
keeping 1 table allocated I don't have to worry about memmory usage
and if a user does need the latest updated table he can log off and
then back in to refresh the table(if nobody else has done so already).
If this sounds like a cludge maybe it is, but right now I question my
knowledge of threading. Functionality can change and maybe updating
the table is best in a worker thread that updates periodicaly on a
timed interval.

So here is the suspected threading issue:

I have a singleton, pretty basic class.

private constructor.
GetInstance
GetTable
SetTable

with a self and table class variable.

the table is created in a javabean that is accessed in the servlet.

A user accessing the table will
GetInstane().Se tTable(javabean .createTable()) if
firstTimeAccess ingTable == true else GetInstane().Ge tTable()

My associate says that the getters and setters are the problem. He
said that if thread1 does myTableRef = GetInstance().G etTable() and
uses the table while thread2 does
GetInstane().Se tTable(javabean .createTable()) that thread1's
myTableRef will change once thread2 does the set.

So my sandBox test is not threaded but I think should be a good enough
example. In my test I tested a "dataType" even though I am not sure
one calls the String class a true dataType and a created class. My
result show that myTableRef will not change once the setTable happens
from another thread. Here is the Code.
public class Singleton {

static Singleton me = null;

private String testDataType = null;
private TestClass testClass = null;

private Singleton(){
}

public static Singleton getInstance(){
if(me==null){
me = new Singleton();
}
return me;
}

public String getDataType(){
return testDataType;
}

public void setDataType(Str ing dataType){
this.testDataTy pe = dataType;
}

public TestClass getTestClass(){
return testClass;
}

public void setTestClass(Te stClass testClass){
this.testClass = testClass;
}

}

public class TestClass{

public int value = 0;

public TestClass(int value){
this.value = value;
}

public TestClass(){}

}

public class SandBox {
public static void main(String[] args) {

Singleton x = Singleton.getIn stance();

String origDataType = "freaky1";
TestClass origTestClass = new TestClass (5);

x.setDataType(o rigDataType);
x.setTestClass( origTestClass);

String retrieved1DataT ype = x.getDataType() ;
TestClass retrieved1TestC lass = x.getTestClass( );

String newDataType = "freaky2";
TestClass newTestClass = new TestClass (10);

x.setDataType(n ewDataType);
x.setTestClass( newTestClass);

String retrieved2DataT ype = x.getDataType() ;
TestClass retrieved2TestC lass = x.getTestClass( );

System.out.prin tln("woot!");
}
}

In Debug mode at the "woot" println I find that the object ID's for
retrieved1DataT ype and retrieved2DataT ype are different as well as the
TestClass counterpart.

This tells me my associate is wrong. But what do you think? Should I
test a multithreaded senerio? Do you think the setters and getters
are thread safe? Will a getters's reference be safe from another
threads setter?
Thanks a bunch!

Erik
Jul 17 '05 #1
0 1444

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
6455
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread...
0
1859
by: James R. Saker Jr. | last post by:
I've got a: "start server thread > Queue object, start server thread <> Queue object, start parsing client < Queue object" application that's got me puzzled. Probably an easy threads issue, but after digging thru Programming Python and Python Recipes sections on Threading class and running thru the examples, I'm still missing something. My...
1
1474
by: Ognjen Bezanov | last post by:
Hi, all Thanks all of you who helped me with the threading and queues issue. I am trying to get it working but I am having problems. When I try to run the following: cmddata = mediaplay.initcommandqueue() #initiates the Queue to send commands down
77
5240
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go...
3
5586
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan dueTime) is always set to 6 days, 23 hours, 59 minutes, .. Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely)....
13
1804
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that. I know of the problems with the worker process doing two things at once from the main thread pool (The old "Sit in a tight loop for 20 seconds and...
4
1992
by: JimD | last post by:
Is this safe? Any pitfalls? I have done threading in regular C# apps, but haven't had a needs to do threading in ASP.Net, until now. The issue I have ran into is this: Our corporate portal application displays the logged in users 10 most recent emails from Exchange via WebDav. The current code is in legacy VB6 and needs to be ported...
2
1525
by: WXS | last post by:
When I see things in .NET 2.0 like obsoletion of suspend/resume because of the public reason MS gives of they think people are using them inappropriately.. use mutex, monitor and other synchronization objects instead and oh by the way you shouldn't be using them as they can cause deadlock and other major problems, screams bug or threading...
0
3500
by: R K | last post by:
I am delevoping a Scheduler module whose functionality is to load the Scheduled Item Details every day (For this I have created a System.Threading.TimerCallBack with Timespan 1 day) in a stack. Once the stack is loaded I look for the qualified items every one minute (I create an another TimerCallBack thread). This Scheuler module needs to be...
126
6658
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard: http://www.cse.wustl.edu/~schmidt/ACE.html the same way that the STL (and subsequently BOOST) have been subsumed? Since it already runs on zillions of platforms, they have...
0
7895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5374
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3818
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1433
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.