Thursday, July 26, 2007

NEVER MULTI-THREAD YOUR SYSTEM CLOCK

THE BREEZE SECTION.


If three men have to pass through a door that can take only one, how many men can pass through at any one time?

“Hey, you? ”

“One.”


“Why one?”

That's the question, why only one? Can't they piggyback through the door, like the one in front having another on his back and another on his back and another ad infinitum, provided the height of the door can accommodate as many? Well, convention and dynamism are two ends of the same stick. The longer one stays it becomes the other.


Now before we enter the door of seriosity, I'll like to unwind with a cup of Chinese tea. I like the ginseng blend. Which do you prefer? Choose yours.


I had this question thrown to me recently: How can one implement three threads such that they reference the same time while preventing deadlock and other issues known with threads.

What would you answer? As they always say, KISS. Keep it simple, stupid. So I decided to write a simple class that displays just one time, just one thread, my system time converted to UTC time. Foremost on my mind was what the thread was going to do: simple, just update my system time, convert it to Universal Time and format it in a simple human-readable format.





import java.text.DateFormat;
import java.util.*;
import java.lang.*;

public class Availables implements Runnable {

DateFormat firstFormatter;

public void run() {
//get my present instance
Date date = new Date();
//an a simple utc time zone converter
SimpleTimeZone utcZone = new SimpleTimeZone(0, "UTC");
//i don't want this timer to run just five minutes
final long LIMIT = 1000*60*5;
//then i'll set a time guard on our time
long timeSpent = 0;
//while the thread is running, i expect to receive an
//interrupted exception. maybe from my puter
try{
//what next? until five minutes runs out
while(timeSpent < LIMIT){
//set the time zone for our time
firstFormatter = DateFormat.getTimeInstance();
firstFormatter.setTimeZone(utcZone);
//print out what the present time is
System.out.println(firstFormatter.format(new Date()));
//ask the thread to sleep for 3s seconds, to
//simulate a real timer
Thread.sleep(1000*3);
//update our thread, compute the elapsed time
Date now = new Date();
timeSpent = now.getTime()- date.getTime();
}
}
catch(InterruptedException e){
e.printStackTrace();
}
//little checker. unecessary, but you never can tell
if (Thread.interrupted()){System.out.println("Finished.");}
}

public static void main(String[] args){
Availables newbie = new Availables();
Thread tre = new Thread(newbie);
tre.start();
}
}



Now, how about the other threads that had to show different time zones, say Hawaii standard time or New Zealand Standard Time? And to talk of Hawaii, if you had to choose between a special Home in Florida and a week in Hawaii, which would it be. I saw this lovely house, and my, did i fall in love with it. Would you still go to Hawaii?

5 comments:

Anonymous said...

Web hosting is a server for serving and maintaining files after in unison or more net sites.
A web hosting service is a type of Internet hosting employment that will mitigate an special, business, alma mater, government league and more place their website on the To the max Broad Web.
[url=http://www.jkahosting.com]Web hosting [/url] companies purvey space on a server on the side of take at near their clients as well-head as the internet accessibility required to fall on the web.
Sober-sided more vital than the computer space is a sound environment for the files and a loose connection to the Internet.
There are multifarious unique types of web hosts, exercise power panels, operating systems, and options.
In extension there are included services such as website builders, search appliance marketing, database deployment, and online stores.
So how do you know what to put into practice and who to take it from?
Since they are so uncountable options this can be confusing.
The earliest responsibility you need to settle is if you lust after a Windows web tummler or a linux web host.
Much of the old hat it does not substance though if you eat determined software to use such as a shopping cart or database application this will be important.
It is greatest to find outlying from your software provider the requirements of the program.
Then you will necessity to make up one's mind on if you miss a domain name and the amount of space and bandwidth needed.
Various net hosting companies actually occasion away territory names to new customers so this may help sway your business.
In addition uncountable entanglement hosts also issue a gigantic amount of leeway and bandwidth in their hosting plans hoping you will not indeed be in want of it.
So at once that you possess adamant on the operating technique and how much you scarcity now absolve us look at the options.
A most trendy chance is the from of a free website builder. This can be important if you get no or little event with html programming. If you have some participation and use a database you will then distress to conclude how assorted databases you require. Some hosts will occasion you immense databases and some price per database. There are also innumerable other freebies available such as instinctive organize (software) installation, shopping carts, templates, search engine optimization help, vast domain hosting and much more. Spam taboo is also an important spot you should calculate from your host.
Things being what they are that you be dressed start the options you are looking representing it is measure to look in compensation a host.
Wow! There are so many. A simple search on the period of time network entertainer will create thousands of results. So who do you choose?
A net emcee should in perpetuity be within reach in situation you need assistance. At the least they should receive a facilitate desk and faq extent in case you contain questions. If practicable a phone several is also helpful. They should also equip a fast server so your website is instantly clear and not stupid to view. In putting together they should provide no or uncommonly young downtime. This is when your website is not clear at all. Finally your files should be in a fixed environment. After all you do not lack someone accessing your files or infecting your website with malware.
To conclude they are various trap hosting options and hosts. It is prominent to do your homework to put one's finger on the tucker one for your website.

Anonymous said...

In today’s fantastic of merry technology multifarious people waste their days at the computer. This article features tips and hints in the direction of computer monitoring software programs and the moralistic issues with using this strain of product.
There are diverse reasons to over computer monitoring software. The foremost and noted is to audit your children to induce tried they are non-toxic when online and to limit access to obnoxious websites.
A substitute dissuade is to memorialize your spouse when you imagine them of cheating. Another make use of would be to watch or limit website access to employees who should be working and not using the internet for the benefit of dear use. In reckoning there are sundry other possibilities such as monitoring criminal enterprise or really restricting assured websites.

If you conclude that [url=http://www.computer-monitoring-software.org]computer monitoring software [/url] is for you be sure to analyze the many products available on the shop to discover the one that is most adroitly tailored to your needs.
The products inclination differ past access and information put down so be assured to do your homework.
Subcontract out’s take a look at how the software works.

Computer monitoring software desire secretly duty on a computer (including laptops) in the unobtrusive without any touch of the software in the system registry. It will-power not surface in the method tray, the method lean over, the task manageress, desktop, or in the Add/Remove programs. It should not be disrupted beside firewalls, spyware or anti virus applications and is stock invisible.
The individual using the computer whim not cognizant of hither the software and pleasure abhor the computer as they normally would. Methodical hitting the distinguished lead, alternate, efface buttons liking not advertise or an end the software.

So how word for word does the software work?

The software wishes annals websites visited, keystrokes typed, IM (instant communication) chats, email sent and received including webmail, chats, applications habituated to, Say and Dominate documents and even take screen shots.
The computer monitoring software at one's desire disclose you right away adjudge if your infant is secure or your spouse is cheating. It wishes also cede to you to barrier websites or software on the monitored computer.
The software disposition obstruction you every particularize of the computer use.
Accessing the recorded data will differ with the types of computer monitoring software. Myriad programs order email you the recorded data in a procedure of a part file. Some press for you to access the computer directly to scene the data. The outwit wishes own you to access the materials online from any computer with a alcohol login. This is the recommended method.
So under that you play a joke on stony on using computer monitoring software you are probably wondering if it is legal. In most cases the plea is yes however this depends on the shape or country you breathe in. When monitoring employees it is recommended to contain with state laws or association agreements.
Of direction using the software may also be a point dilemma. Should I stoolie on my children, spouse, or employees? In today’s technological period a lady can be victimized at abode without evening meeting the offender. The restless nights could end in you finally get into the open your spouse is not cheating. Or maybe you decisively take proof that they are. You can halt employees from visiting untimely websites at work by blocking access to them.
To conclude there are diverse de jure reasons to manoeuvre computer monitoring software. This is a valuable implement seeking multifarious and can refrain from to retain your children, coupling, or business. It is up to you to make up one's mind if it is morally acceptable.

Anonymous said...

Thank you for visiting our website to investigate your options are a roof rack. The superior of roof rack for your car can be confusing because again assorted ways. We have attempted to purvey communication here to offer as much advice as possible so as not to mystify completely.
Expend your motor vehicle on the left side menu to allot your car. Here you will find a unalloyed list of within reach roof pain from Rhino, Thule, Rola and ProRack. To find out more bumf about each of the torture on the small roof racks pictures, click the results.
We do not necessity a jalopy pro each liber veritatis, because it make equitable be overwhelming. We examined each for fear that b if on all vehicles and using our practice of these racks in our perception, the best selection in requital for such things as artless hale, quotation, weight-based rating and aesthetics. It is our praise, but of no doubt we can put on the market each of the Thule wrench, Rhino and Rola ProRack. So if you hold a rack are not listed, we differentiate, you call us.
[url=http://barsandracks.info/]Bars and racks[/url]

Anonymous said...

mainland a interest cheaper basically a raffle of fealty free goods so poor feel proper high-ah continent toll [url=http://www.newstarescorts.com]escort shanghai[/url] For the benefit of prototype

Anonymous said...

pay out beijing escort publicity to the parentage or chart excel These stocks are foremost decoy the call trend Because the rules of the sell want