tag:blogger.com,1999:blog-169697292024-03-13T00:19:02.401-07:00Patricio EchagueAnonymoushttp://www.blogger.com/profile/02865743639141548921noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-16969729.post-36660755351053133332013-10-13T15:17:00.000-07:002013-10-14T11:47:12.063-07:00Different strategies to monitor Storm ProcessorThis topic has come up multiple times in <a href="http://storm-project.net/" target="_blank">storm</a> mailing list so I figure it would good to put some ideas together as well as sharing some hands on experience on how to monitor storm topologies.<br />
We can group the monitoring metrics into these categories.<br />
<br />
<ul>
<li>Independent metrics from each particular topology</li>
<li>JVM metrics</li>
<li>Storm metrics (i.e: tuples per minutes)</li>
<li>Miscellaneous (when using Kafka Spouts)</li>
</ul>
<br />
<b><span style="font-size: large;">Independent metrics from each particular topologies</span></b><br />
<b><br /></b>
Each topology is different and is going to have different metrics to publish. This is not different than any other way you can monitor you web application. The key here is how to ship application specific metrics into a data collector for plotting and alerting. Just for completeness it's worth mentioning some.<br />
<br />
<ul>
<li><a href="http://metrics.codahale.com/" target="_blank">Yammer Metrics</a> with specific backend writer. Some good ones are <b><a href="https://github.com/etsy/statsd/" target="_blank">Statsd</a>,</b> <b><a href="http://ganglia.sourceforge.net/" target="_blank">Ganglia</a> </b>and <b><a href="http://graphite.wikidot.com/" target="_blank">Graphite</a>.</b></li>
</ul>
<ul>
<li><b>Statsd</b> directly (useful when wanting to see aggregated data). Here you would just instrument your code to output specific metrics. Statsd will later on (normally every minute) aggregate the received data and write to a backend such as Ganglia or graphite.</li>
</ul>
<br />
<br />
<b><span style="font-size: large;">JVM metrics</span></b><br />
<b><br /></b>
This category is to group information such as Heap size, Heap used, GC time among others.<br />
<br />
Something I have tried in the past was to co-locate <a href="http://www.jmxtrans.org/" target="_blank">JMXTrans</a> in each Storm box and via <b>Chef</b> come up with the right ports to connect to. For example if in a particular box I set up two Storm workers -6700 and 6701- and enable JMX for each of them as follows (via storm.yaml file):<br />
<br />
<pre class="brush: java; ruler: true; first-line: 1;">-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=1%ID%
</pre>
<br />
Note that "<b><i>1%ID%</i></b>" will be replaced with <i><b>16700</b></i> and <i><b>16701</b></i> respectively. This predictability lets me search via chef how many workers are there in each box (the workers are Chef attributes) , co-colocate JMXtrans service in the same box and dynamically set up JMXTrans config file for each worker.<br />
<br />
Below is how I tell Chef how many workers I have in each machine.<br />
<br />
<pre class="brush: ruby; ruler: true; first-line: 1;">default[:storm][:workers] = [6700, 6701]
</pre>
<br />
This is an example of a JMXTrans config file for extracting data from the JVM that writes to a Ganglia collector.<br />
<br />
<pre class="brush: js; ruler: true; first-line: 1;">{
"servers" : [ {
"port" : "<%= @service_port%>",
"host" : "127.0.0.1",
"alias" : "<%= node.name%>:<%= node.name%>",
"queries" : [ {
"outputWriters" : [ {
"@class" : "com.googlecode.jmxtrans.model.output.GangliaWriter",
"settings" : {
"groupName" : "jvmheapmemory",
"port" : <%= node[:ganglia][:port]%>,
"host" : "<%= node[:ganglia][:collector_host]%>"
}
} ],
"obj" : "java.lang:type=Memory",
"resultAlias": "<%= @service_name%>-heap",
"attr" : [ "HeapMemoryUsage", "NonHeapMemoryUsage" ]
}, {
"outputWriters" : [ {
"@class" : "com.googlecode.jmxtrans.model.output.GangliaWriter",
"settings" : {
"groupName" : "jvmcmsoldgen",
"port" : <%= node[:ganglia][:port]%>,
"host" : "<%= node[:ganglia][:collector_host]%>"
}
} ],
"obj" : "java.lang:name=CMS Old Gen,type=MemoryPool",
"resultAlias": "<%= @service_name%>-cmsoldgen",
"attr" : [ "Usage" ]
} ],
"numQueryThreads" : 2
} ]
}
</pre>
<br />
<u>Some notes about this approach</u>:<br />
<ul>
<li>When a worker is down, JMXTrans errors out so I had to set up a cron job that restarts JMXTrans service every 30 minutes to make sure I don't lose metrics.</li>
<li>High maintenance since it requires keeping both JMXTrans config and storm config in sync.</li>
</ul>
<br />
<br />
A second approach is to use <a href="http://metrics.codahale.com/" target="_blank">Yammer Metrics</a> <a href="http://metrics.codahale.com/manual/jvm/" target="_blank">JVM Instrumentation</a>. For it to work you have to use a Reporting Writer to write the metrics to a backend collector. I use Ganglia and Statsd -<i>which does not appear in the list</i>-. <a href="https://github.com/relateiq/metrics-statsd" target="_blank">Here there is an adapted version of a Statsd reporter</a> where we suppress specific metrics (Histograms) since statsd already constructs histograms for us. Yammer Metrics only uses gauges to publish the data so suppressig histograms doesn't seem to be a big deal.<br />
The beauty of this is that you no longer have to keep two services config in sync. As soon as storm launches a topology it will start emitting JVM metrics.<br />
<br />
This is a screenshot plotted with Graphite which is one of the backends statsd writes data to.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZQrvVnhyphenhyphenlTJZ34LVYukvUsq63hv4p82Lfh4QvOAn0gliTJ7RQIgLqYKG1F2LmraCBP9wD0LaKRMGmfeh_shRcL6k6zaQMQgk2K_Zxn6F_25meNWY1_ahuH-0KUswENFKbu_5K/s1600/jvm-heaps.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="210" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZQrvVnhyphenhyphenlTJZ34LVYukvUsq63hv4p82Lfh4QvOAn0gliTJ7RQIgLqYKG1F2LmraCBP9wD0LaKRMGmfeh_shRcL6k6zaQMQgk2K_Zxn6F_25meNWY1_ahuH-0KUswENFKbu_5K/s320/jvm-heaps.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b><span style="font-size: large;">Storm Metrics</span></b></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
By "Storm Metrics" I meant metrics from Storm framework itself, such as <i>Tuples Per minute, Latency, Capacity, etc.</i></div>
<div class="separator" style="clear: both; text-align: left;">
At the time of writing this post we(<a href="https://www.relateiq.com/" target="_blank">RelateIQ</a>) are using Storm 0.8.3 which has some support to attach hooks to components (Spouts and Bolts) and storm calls those hooks with information about the tuples that are being emitted, acked and failed. This is an example of a Hook that writes those metrics to Yammer Metrics meters which are send out to Statds (in our case) every minute.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
<pre class="brush: java; ruler: true; first-line: 1;">public class MeteredSpoutHook extends BaseMeteredHook {
private Meter emittedTuples;
private Meter ackedTuples;
private Meter failedTuples;
public MeteredSpoutHook() {}
@Override
public void emit(EmitInfo emitInfo) {
emittedTuples.mark();
}
@Override
public void spoutAck(SpoutAckInfo spoutAckInfo) {
ackedTuples.mark();
// TODO Do something with: spoutAckInfo.completeLatencyMs
}
@Override
public void spoutFail(SpoutFailInfo spoutFailInfo) {
failedTuples.mark();
// TODO Do something with: spoutFailInfo.failLatencyMs
}
@Override
public void init(TopologyContext context, String topologyName, String label) {
MetricName emittedTuplesMetricName = new MetricName("Topology-" + topologyName, "Spout_" + label, "EmittedTuples");
emittedTuples = Metrics.newMeter(emittedTuplesMetricName, "tuples", TimeUnit.MINUTES);
MetricName ackedTuplesMetricName = new MetricName("Topology-" + topologyName, "Spout_" + label, "AckedTuples");
ackedTuples = Metrics.newMeter(ackedTuplesMetricName, "tuples", TimeUnit.MINUTES);
MetricName failedTuplesMetricName = new MetricName("Topology-" + topologyName, "Spout_" + label, "FailedTuples");
failedTuples = Metrics.newMeter(failedTuplesMetricName, "tuples", TimeUnit.MINUTES);
}
}
</pre>
<br />
<span style="font-size: large;"><b>Miscellaneous</b></span><br />
<br />
If you happen to be using Kafka Spouts as one of your spouts implementation, a project I found very useful was stormkafkamon (<a href="https://github.com/otoolep/stormkafkamon" style="white-space: normal;" target="_blank">original</a><span style="white-space: normal;"> and </span><a href="https://github.com/relateiq/stormkafkamon" style="white-space: normal;" target="_blank">fork which fixes some bugs</a><span style="white-space: normal;">). It is intended to work in conjunction with <a href="https://github.com/nathanmarz/storm-contrib/tree/master/storm-kafka" target="_blank">Kafka spout from storm-contrib</a>. This Spout stores a watermark in Zookeeper and stormkafkamon reads the latest offset from Kafka broker and from Zookeeper and shows the delta in a nice formatted way.
<br />
</span><br />
<pre class="brush: bash; ruler: true; first-line: 1;">+--------------+----------+-----------+--------------+--------------+-------------+----------+--------------+-------+
| Broker | Topic | Partition | Earliest | Latest | Depth | Spout | Current | Delta |
+--------------+----------+-----------+--------------+--------------+-------------+----------+--------------+-------+
| kafka-broker | TOPIC_1 | 0 | 17314225754 | 18492471767 | 1178246013 | TOPIC_1 | 18492470390 | 1377 |
| kafka-broker | TOPIC_2 | 0 | 85228601970 | 89208988484 | 3980386514 | TOPIC_2 | 89208987752 | 732 |
| kafka-broker | TOPIC_3 | 0 | 457686650224 | 484187159862 | 26500509638 | TOPIC_3 | 484187157164 | 2698 |
+--------------+----------+-----------+--------------+--------------+-------------+----------+--------------+-------+
Number of brokers: 1
Number of partitions: 3
Total broker depth: 31659142165
Total delta: 4807
</pre>
<br />
And with some bash script foo you could add a cron job that runs it once a minute, parse the data and send it to statsd (Cheers to my coworker Jón Grétarsson for writing this script).<br />
<br />
<br />
<hr>
<br />
If you feel like the explanation is not accurate, have specific questions or have any other feedback please shoot me an email to patricioe at gmail dot com.<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/02865743639141548921noreply@blogger.com10tag:blogger.com,1999:blog-16969729.post-68583656486340880052013-06-15T12:20:00.000-07:002013-06-15T12:20:28.370-07:00Notes From The Cassandra Summit 2013It was nice to see my former Datastax coworkers during the summit that took place at fort Mason in San Francisco. As expected, each Cassandra summit is becoming more and more crowded which proves that the technology is getting more popular in the industry. I was very impressed and happy at the same time to see that all sort of companies are moving towards using Cassandra for different areas of their stack. Few of them include <a href="http://planetcassandra.org/blog/post/instagram-making-the-switch-to-cassandra-from-redis-75-instasavings">Instagram replacing their sharded Redis cluster</a> with a Cassandra one running on SSDs serving peaks of 20k write operations 15k reads per second, and Spotify serving their 24+ million users out of Cassandra cluster with about 300 Cassandra nodes between the 24 different services that use the database to store 50TB of data.<br />
Solid state Drives (SSDs) give really high throughput specially if your access pattern is mostly random. If you manage your own hardware you should definitely consider SSDs for the data partition. If AWS is your call then hi1.4xlarge is your friend.Anonymoushttp://www.blogger.com/profile/02865743639141548921noreply@blogger.com1tag:blogger.com,1999:blog-16969729.post-56470903561731211522013-06-01T15:19:00.000-07:002013-06-01T15:19:06.133-07:00Distributed Cassandra-based Locks in Hector ClientAfter almost 3 years of not updating this blog I decided that writing about the latest interesting feature in Hector was a good excuse to break the ice. I wrote the <a href="https://github.com/hector-client/hector/commit/fc1c57e3a20acf34d1963b8901ff9c176f126395" target="_blank">first implementation</a> of distributed lock support for <a href="http://hector-client.github.io/hector/build/html/index.html" target="_blank">Hector</a> on July 15th 2012 and Todd Nine took it to the next step.<br />
The feature is an implementation of Dominic Williams's <a href="http://media.fightmymonster.com/Shared/docs/Wait%20Chain%20Algorithm.pdf" target="_blank">Wait Chain</a> with minor adjustments, backed 100% by Cassandra, which means that it is horizontally scalable.<br />
<br />
The framework is composed by three main entities:<br />
<ul>
<li><span style="font-family: Courier New, Courier, monospace;">HLock</span> : Self explanatory. It is the lock we are trying to acquire.</li>
<li><span style="font-family: Courier New, Courier, monospace;">HLockManager</span> : The entity responsible to acquiring and releasing the lock, and</li>
<li><span style="font-family: Courier New, Courier, monospace;">HLockManagerConfigurator</span> : Responsible to configuring the lock system. HLMC from now on.</li>
</ul>
<div>
<br /></div>
<div>
HLMC defines important properties needed for the normal operation of the lock system. Hector implements this feature by storing information in <b>HLocks</b> column family under a specific keyspace <b>HLockingManager</b> with a default <b>replication factor of 3</b>. Additionally <b>row cache is enabled</b> by default and the <b>locks last 5 seconds</b> after which the lock will expire.<br />
<br />
All the above mentioned properties can be change via HLMC.<br />
<br />
<h3>
How to initialize the locking system</h3>
</div>
<div>
<br /></div>
<div>
The following snippet of code shows how to initialize the framework and can be place along to where you set up <a href="http://hector-client.github.io/hector/build/html/content/guice_integration.html" target="_blank">Hector's CassandraHostConfigurator</a></div>
<pre class="brush: java; ruler: true; first-line: 1; highlight: [3, 5, 6]">
// Initialize Locking Framework
cluster = getOrCreateCluster("MyCluster", getCHCForTest());
HLockManagerConfigurator hlc = new HLockManagerConfigurator();
hlc.setReplicationFactor(1);
lm = new HLockManagerImpl(cluster, hlc);
lm.init();
</pre>
<h3>
Acquiring and Releasing Locks</h3>
<div>
<br /></div>
<div>
This snippet shows to to use the locks. It assumes you hold an instance of LockManager somewhere. Guice and Spring are good frameworks to solve this problem.<br />
<pre class="brush: java; ruler: true; first-line: 1; highlight: [3,7]">HLock lock = lm.createLock("/Users/patricioe");
try {
lm.acquire(lock);
// Do something ...
} finally {
lm.release(lock)
}
</pre>
<h3>
Thread safety</h3>
<div>
<br /></div>
<div>
The implementation of <b>HLockManager</b> (<i>HLockManagerImp</i>) is <b>thread safe</b> and thus can be share across different threads. Instances of <b>HLock</b> (<i>HLockImp</i>) on the other hand are state-full and <b>should not be</b> share across threads. They are meant to be created and release within a short period of time (5 Seconds by default).</div>
<div>
<br /></div>
<h3>
Miscellaneous </h3>
<div>
<br /></div>
<div>
Besides the fact that some people are using this feature I recommend to you to give it a try and send us feedback or questions to <a class="reference external" href="mailto:hector-users%40googlegroups.com" style="background-color: white; color: #2491cf; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; font-size: 14px; line-height: 21px;">hector-users@googlegroups.com</a> or here in this blog. Hope you enjoyed the reading.</div>
<div>
<br /></div>
<div>
You should follow me on Twitter <a href="https://twitter.com/patricioe" target="_blank">@patricioe</a></div>
<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/02865743639141548921noreply@blogger.com2tag:blogger.com,1999:blog-16969729.post-73425224198155850022010-12-16T15:56:00.000-08:002010-12-22T16:44:53.898-08:00How to create a custom ClockResolution in Hector (0.7.0-x)<div class="separator" style="clear: both; text-align: left;"><br />
</div>Create your own ClockResolution in Hector (as of 0.7.0-22) is easy. We have modified the code a bit to allow Hector clients to define their own implementation if needed. Let's assume we want to create a clock resolution class that generates negative numbers (this is not a useful example. It is only to show how it is possible).<br />
<div class="separator" style="clear: both; text-align: left;">The way to do it is by creating a class that implements<span style="font-family: "Courier New",Courier,monospace;"> me.prettyprint.hector.api.ClockResolution</span></div><br />
<br />
<div class="wp_syntax"><div class="code"><br />
<div class="separator" style="clear: both; font-family: "Courier New",Courier,monospace; text-align: left;"><span style="font-size: small;"> <span style="color: #93c47d;">// Define my own clock resolution.</span></span><span style="font-size: small;"><br />
</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> <b><span style="color: #741b47;">class </span></b>SequentialClockResolution <b style="color: #741b47;">implements </b>ClockResolution {</span><span style="font-size: small;"><br />
</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> <span style="color: #999999;">@Override</span></span><span style="font-size: small;"><br />
</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> <b><span style="color: #741b47;">public long</span></b> createClock() {</span><span style="font-size: small;"><br />
</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> <b><span style="color: #741b47;">return </span></b>System.currentTimeMillis() * -1;</span><span style="font-size: small;"><br />
</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> }</span><span style="font-size: small;"><br />
</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;"> }</span></div></div></div><br />
And now we have to tell Hector to use it. <br />
<br />
<div class="wp_syntax"><div class="code"><span style="font-family: "Courier New",Courier,monospace; font-size: small;"> <span style="font-size: small;"> CassandraHostConfigurator cassandraHostConfigurator = <b><span style="color: #741b47;">new</span></b></span> CassandraHostConfigurator("localhost");</span><span style="font-size: small;"><br style="font-family: "Courier New",Courier,monospace;" /></span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"> cassandraHostConfigurator.setClockResolution(new SequentialClockResolution());</span><br />
</div></div><br />
<span style="font-family: inherit;">As an additional information, this is the class diagram involved in ClockResolution. </span><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7d6GJ1fo4amcLrdTzDDJKkMkCcPQxfb0xCOxmr8pe_pCl6ckmaRiIXiCbnD2MWtfsCoNL3IelK5vjd8UPDm-IQBJ-sGzPJpfEDLidqRxIDNd9YEhd0zZm6yAtJut34xON_rMq/s1600/ClockResolutionClassDiagram.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="379" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7d6GJ1fo4amcLrdTzDDJKkMkCcPQxfb0xCOxmr8pe_pCl6ckmaRiIXiCbnD2MWtfsCoNL3IelK5vjd8UPDm-IQBJ-sGzPJpfEDLidqRxIDNd9YEhd0zZm6yAtJut34xON_rMq/s640/ClockResolutionClassDiagram.png" width="640" /></a></div>Anonymoushttp://www.blogger.com/profile/02865743639141548921noreply@blogger.com5tag:blogger.com,1999:blog-16969729.post-70614380893768785642010-10-18T19:15:00.000-07:002012-06-28T15:32:41.129-07:00Evaluating timestamp resolution algorithms in Hector Framework (Cassandra DB)<div class="MsoNormal">
<b>Motivation:</b><br />
As many of you might know, Java does not provide microseconds granularity. When using <a href="http://cassandra.apache.org/">Cassandra</a> DB you need to make sure that your clients have their clocks in sync. That is the requirement. Other non-relational databases like <a href="http://project-voldemort.com/">Voldemort</a>, this is not necessary (they use Vector Clocks).<br />
If we decided to use milliseconds resolution (what Java provides), sometimes if there are two inserts (or one insert and one delete) within the same millisecond (typical example in Lucandra when updating a row),<br />
the second operation gets discarded as it happens at the same time than the previous request. This is why we had to come up with a way to provide every thread that requests a time a unique timestamp.<br />
<br />
<b>Goal:</b></div>
<div class="MsoNormal">
Evaluate the performance of the three <a href="http://github.com/rantav/hector">Hector </a>time resolution algorithms with Microseconds accuracy. </div>
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>The fully synchronized algorithm guarantees <b>unique</b> timestamp in microseconds per threads and across threads<b>.[1]</b><br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>The second one uses Atomic Longs to accomplish the same goal than the first one, but presents some race condition and the results might not be guaranteed across threads. I contributed this code and it is in Hector branch 6 but not main branch.<b> [2]</b><br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>The third one does not guaranteed that a thread in two consecutives calls obtain the same timestamp. (risk of missing operations as Cassandra discard them if they contain the same timestamp). Currently in hector main branch. <b>[3]</b><br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Conclusion</b>:</div>
<div class="MsoNormal">
The fully synchronized timestamp resolution algorithm present a decent TPS, almost imperceptible comparing with the non-synchronized one and providing a “bullet proof” mechanisms to guarantee unique time resolution within the same thread and across threads as well.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Environment:</b></div>
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Machine: rwc-devlinux5<br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>CPUs: 2 X QC x 3.0gh <br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>RAM: 32 GB<br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>SO: Red Hat (RHEL 5.3)<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>About the test:</b></div>
I included the result of 3 benchmarks. With 8 threads, with 50 and 100(with no warm-up).<br />
<div class="MsoNormal">
Per benchmark, there are 3 sub-benchmark where I compare the behavior of 3 algorithms to calculate the timestamp:</div>
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Fully synchronized<br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Partially synchronized, and (use <i>AtomicLong</i>)<br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Not synchronized at all<br />
<div class="MsoNormal">
Each thread execute a couple of thousand operations.</div>
<div class="MsoNormal">
Each operation does 3 things: </div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> double res = Math.<i>random</i>() * 13;</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> String s = </span><span style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"something"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> + res;</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> TimestampResolutionNotSync.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MIC<wbr></wbr>ROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.createTimestamp();</span></div>
<div class="MsoNormal">
<br />
Before the benchmark, I let the test run 5k operation with no time calculation to warm-up. Without it, the first set of test to be executed always shows a slightly less performance. So I consider it was fair to include the warm-up first. The 100 threads test has not warm-up.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The overall operation is 5,000,000. Regardless the number of threads. This way I can see how fast or slow it works.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>How to interpret the results:</b></div>
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>Look at the attached files. There 2 files per benchmark. (one shows the TPS and media, and the other one shows the CPU usage)<br />
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>For example: 100Threads-15secs-50kops means:<br />
<div style="margin-left: 1in;">
<span style="font-family: 'Courier New';">o<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span>100 threads</div>
<div style="margin-left: 1in;">
<span style="font-family: 'Courier New';">o<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span>Graphic has timeframes of 15 secs</div>
<div style="margin-left: 1in;">
<span style="font-family: 'Courier New';">o<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></span>Each thread perform 50 K operations</div>
-<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span>There are three colors indicating the performance of the three algorithms (Blue, Red and Green)<br />
<span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span><img height="72" src="https://mail.google.com/mail/?ui=2&ik=4e64c08ef3&view=att&th=12bc237a2da96aba&attid=0.0.1&disp=emb&zw" width="268" /><br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: #365f91;">BLUE</span></b>: the createTimestamp method is fully synchronized </div>
<div class="MsoNormal">
<b><span style="color: #00b050;">GREEN</span></b>: Partially synchronized using atomic long with possible race conditions.</div>
<div class="MsoNormal">
<b><span style="color: red;">RED:</span></b> Not synchronized at all with high risk of getting the same timestamp within and across threads.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
</div>
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=Mean&chs=750x400&chxt=x,x,y&chd=t:30.8,38.5,46.2,53.8,61.5,69.2%7C85.0,82.1,84.7,86.4,85.1,68.5%7C69.2,76.9,84.6,92.3,100.0%7C82.3,76.9,80.0,80.1,80.3%7C0.0,7.7,15.4,23.1,30.8%7C100.0,75.8,76.9,79.9,80.7&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-5-1000000%7CSimpleNotSync-5-1000000%7CSync-5-1000000&chxr=2,0,0.0&chxl=0:%7C17:41:45%7C17:42:15%7C17:42:45%7C17:43:15%7C17:43:45%7C17:44:15%7C17:44:45%7C1:%7CTime&chxp=0,0.0,15.4,30.8,46.2,61.5,76.9,92.3%7C1,50&chg=7.7,10" /><br />
<span style="font-size: small;"><i>Case 1: 8 Threads - 1000 K operations.</i></span><br />
<span style="font-size: small;"><i>Note: Lower values are better. It shows the media of each algorithm. </i></span><br />
<br />
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=TPS&chs=750x400&chxt=x,x,y&chd=t:30.8,38.5,46.2,53.8,61.5,69.2%7C35.6,96.9,92.0,91.9,94.9,10.1%7C69.2,76.9,84.6,92.3,100.0%7C84.1,96.9,95.1,93.1,52.1%7C0.0,7.7,15.4,23.1,30.8%7C60.6,99.8,100.0,99.1,61.8&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-5-1000000%7CSimpleNotSync-5-1000000%7CSync-5-1000000&chxr=2,0,79116.6&chxl=0:%7C17:41:45%7C17:42:15%7C17:42:45%7C17:43:15%7C17:43:45%7C17:44:15%7C17:44:45%7C1:%7CTime&chxp=0,0.0,15.4,30.8,46.2,61.5,76.9,92.3%7C1,50&chg=7.7,10" /><br />
<span style="font-size: small;"><i>Case 1: 8 Threads - 1000 K operations.</i></span><br />
<span style="font-size: small;"><i>Note: TPS (transactions per second). Higher values are better here. </i></span><br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZbtwmS1yTRrhsNJNxAUEmRm-huj0lb5W047iTQycnPVbwQDKP6jWt5GYKANEDhtv49XgDtS_CWdUHIZ38I2v3rfVGa6zLd6eQ451DUh13CUmbS9PxrHBjWdvRW6Q2RcohB5Ht/s1600/8Threads-1000kops-cpu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="304" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZbtwmS1yTRrhsNJNxAUEmRm-huj0lb5W047iTQycnPVbwQDKP6jWt5GYKANEDhtv49XgDtS_CWdUHIZ38I2v3rfVGa6zLd6eQ451DUh13CUmbS9PxrHBjWdvRW6Q2RcohB5Ht/s320/8Threads-1000kops-cpu.png" width="320" /></a></div>
<div style="text-align: center;">
<span style="font-size: small;"><i>Case 1: CPU and memory</i>. </span><span style="font-size: small;"><i>Notice how the cpu usage stays constant during the execution of the three test cases (a spike down indicates the end and beginning of the next test).</i></span></div>
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=Mean&chs=750x400&chxt=x,x,y&chd=t:68.8,75.0,81.2,87.5,93.8,100.0%7C81.7,78.6,75.8,75.6,78.8,76.3%7C0.0,6.2,12.5,18.8,25.0,31.2%7C77.9,72.1,74.2,75.2,73.9,79.7%7C31.2,37.5,43.8,50.0,56.2,62.5,68.8%7C99.4,83.6,84.6,80.6,80.1,84.7,100.0&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-8-1000000%7CSimpleNotSync-8-1000000%7CSync-8-1000000&chxr=2,0,0.0&chxl=0:%7C17:40:00%7C17:40:40%7C17:41:20%7C17:42:00%7C17:42:40%7C17:43:20%7C17:44:00%7C17:44:40%7C17:45:20%7C1:%7CTime&chxp=0,0.0,12.5,25.0,37.5,50.0,62.5,75.0,87.5,100.0%7C1,50&chg=6.2,10" /><br />
<span style="font-size: small;"><i>Case 1b: 8 Threads - 1000 K operations with warmup (5K operation per thread and non-synchronized is first)</i></span><br />
<span style="font-size: small;"><i>Note: Including a warmup and switching the non-synchronized operation in the first place seems to make a different. The lowest media is of course for the non-synchronized algorithm, the highest value is for the fully synchronized algorithm and as expected, the algorithm that uses AtomicLong is slightly in between (lower values are better).</i></span><br />
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=TPS&chs=750x400&chxt=x,x,y&chd=t:68.8,75.0,81.2,87.5,93.8,100.0%7C60.7,99.1,98.5,99.0,100.0,54.6%7C0.0,6.2,12.5,18.8,25.0,31.2%7C70.0,98.2,98.9,98.9,98.6,47.2%7C31.2,37.5,43.8,50.0,56.2,62.5,68.8%7C17.0,97.7,96.3,97.5,98.2,94.4,10.7&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-8-1000000%7CSimpleNotSync-8-1000000%7CSync-8-1000000&chxr=2,0,78154.7&chxl=0:%7C17:40:00%7C17:40:40%7C17:41:20%7C17:42:00%7C17:42:40%7C17:43:20%7C17:44:00%7C17:44:40%7C17:45:20%7C1:%7CTime&chxp=0,0.0,12.5,25.0,37.5,50.0,62.5,75.0,87.5,100.0%7C1,50&chg=6.2,10" /><br />
<span style="font-size: small;"><i>Case 1b: 8 Threads - 1000 K operations with warmup (5K operation per thread and non-synchronized is first)</i></span><br />
<span style="font-size: small;"><i>Note: </i>In this second graph second case (TPS), the three algorithms seem to perform just as good. (highest values are better)</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="text-align: center;">
<span style="font-size: x-small;"><i><br />
</i></span></div>
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=Mean&chs=750x400&chxt=x,x,y&chd=t:71.4,78.6,85.7,92.9,100.0%7C86.8,80.8,80.6,82.4,88.2%7C0.0,7.1,14.3,21.4,28.6%7C84.8,81.8,79.5,79.5,74.4%7C35.7,42.9,50.0,57.1,64.3%7C100.0,87.6,87.9,89.7,90.1&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-50-100000%7CSimpleNotSync-50-100000%7CSync-50-100000&chxr=2,0,0.0&chxl=0:%7C18:46:30%7C18:47:00%7C18:47:30%7C18:48:00%7C18:48:30%7C18:49:00%7C18:49:30%7C18:50:00%7C1:%7CTime&chxp=0,0.0,14.3,28.6,42.9,57.1,71.4,85.7,100.0%7C1,50&chg=7.1,10" /><br />
<span style="font-size: small;"><i>Case 2: 50 Threads - 100 K operations with warmup (lower values are better)</i>.</span><br />
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=TPS&chs=750x400&chxt=x,x,y&chd=t:71.4,78.6,85.7,92.9,100.0%7C83.0,100.0,99.6,99.3,55.6%7C0.0,7.1,14.3,21.4,28.6%7C47.5,99.0,99.8,97.9,93.3%7C35.7,42.9,50.0,57.1,64.3%7C65.7,98.3,97.2,97.9,78.3&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-50-100000%7CSimpleNotSync-50-100000%7CSync-50-100000&chxr=2,0,76197.2&chxl=0:%7C18:46:30%7C18:47:00%7C18:47:30%7C18:48:00%7C18:48:30%7C18:49:00%7C18:49:30%7C18:50:00%7C1:%7CTime&chxp=0,0.0,14.3,28.6,42.9,57.1,71.4,85.7,100.0%7C1,50&chg=7.1,10" /><br />
<span style="font-size: small;"><i>Case 2: 50 Threads - 100 K operations with warmup(higher values are better)</i>.</span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzlQhF7XFouI1C_kgmqoIlJK1wN0JVGk7STPrJs7L07MSd61axfcGbLP8DkVgkodlZq9cBKoXxXRYXpm16Tw8hXL0pEy-grlr42S_MUBUpRN96aPHwFBW6qOhHiwQu5mQHlziz/s1600/50Threads-100Kops-cpu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzlQhF7XFouI1C_kgmqoIlJK1wN0JVGk7STPrJs7L07MSd61axfcGbLP8DkVgkodlZq9cBKoXxXRYXpm16Tw8hXL0pEy-grlr42S_MUBUpRN96aPHwFBW6qOhHiwQu5mQHlziz/s320/50Threads-100Kops-cpu.png" width="309" /></a></div>
<div style="text-align: center;">
<span style="font-size: small;"><i>Case 2: CPU and memory</i>. </span><span style="font-size: small;"><i>Notice how the cpu usage stays constant during the execution of the three test cases (a spike down indicates the end and beginning of the next test).</i></span></div>
<br />
<br />
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=Mean&chs=750x400&chxt=x,x,y&chd=t:26.7,33.3,40.0,46.7,53.3,60.0,66.7%7C100.0,81.6,91.4,89.8,74.0,79.3,78.5%7C66.7,73.3,80.0,86.7,93.3,100.0%7C96.6,84.0,83.8,79.7,79.8,75.3%7C0.0,6.7,13.3,20.0,26.7%7C77.8,63.2,66.5,66.9,70.0&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-100-50000%7CSimpleNotSync-100-50000%7CSync-100-50000&chxr=2,0,0.0&chxl=0:%7C17:27:45%7C17:28:15%7C17:28:45%7C17:29:15%7C17:29:45%7C17:30:15%7C17:30:45%7C17:31:15%7C1:%7CTime&chxp=0,0.0,13.3,26.7,40.0,53.3,66.7,80.0,93.3%7C1,50&chg=6.7,10" /><br />
<span style="font-size: small;"><i>Case 2: 100 Threads - 50 K operations.</i></span><br />
<br />
<br />
<img src="http://chart.apis.google.com/chart?cht=lxy&chtt=TPS&chs=750x400&chxt=x,x,y&chd=t:26.7,33.3,40.0,46.7,53.3,60.0,66.7%7C8.7,88.5,80.5,79.9,88.4,84.4,24.8%7C66.7,73.3,80.0,86.7,93.3,100.0%7C54.5,80.9,82.8,84.7,85.9,66.4%7C0.0,6.7,13.3,20.0,26.7%7C83.5,100.0,97.1,95.6,79.0&chco=ff0000,00ff00,0000ff&chm=d,ff0000,0,-1,5.0%7Cd,00ff00,1,-1,5.0%7Cd,0000ff,2,-1,5.0&chdl=NotSync-100-50000%7CSimpleNotSync-100-50000%7CSync-100-50000&chxr=2,0,73219.5&chxl=0:%7C17:27:45%7C17:28:15%7C17:28:45%7C17:29:15%7C17:29:45%7C17:30:15%7C17:30:45%7C17:31:15%7C1:%7CTime&chxp=0,0.0,13.3,26.7,40.0,53.3,66.7,80.0,93.3%7C1,50&chg=6.7,10" /><br />
<span style="font-size: small;"><i>Case 3: 100 Threads - 50 K operations.</i></span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWKvsoZzIo506hZO1gvk2vRgfAvBpxPtR4D0NgWX5Rx26DP6OZg-tt3F-Wx-GEfh4QHKsbRLHC10HbLZ98DJWZsXa-WxmNZShDkHK-aChbubJcQvidVB23qZ8W4V6POqxwtO7c/s1600/100Threads-50kops-cpu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="304" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWKvsoZzIo506hZO1gvk2vRgfAvBpxPtR4D0NgWX5Rx26DP6OZg-tt3F-Wx-GEfh4QHKsbRLHC10HbLZ98DJWZsXa-WxmNZShDkHK-aChbubJcQvidVB23qZ8W4V6POqxwtO7c/s320/100Threads-50kops-cpu.png" width="320" /></a></div>
<div style="text-align: center;">
<span style="font-size: small;"><i>Case 3: CPU and memory</i>. </span><span style="font-size: small;"><i>Notice how the cpu usage stays constant during the execution of the three test cases (a spike down indicates the end and beginning of the next test).</i></span></div>
<br />
<br />
<div class="MsoNormal">
<b>Source code</b></div>
<div class="MsoNormal">
<b>[1]</b></div>
<br />
<div class="wp_syntax">
<div class="code">
<br />
<div class="MsoNormal">
<b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">enum</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <span style="background-attachment: scroll; background-color: silver; background-image: none; background-position: 0% 0%; background-repeat: repeat repeat;">TimestampResolutionFullySynchr<wbr></wbr>onized</span> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">SECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MILLISECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MICROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * The last time value issued. Used to try to prevent duplicates.</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">static</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> = -1;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">static</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">final</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">ONE_THOUSAND</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> = 1000L;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">synchronized</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> createTimestamp() {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current = System.<i>currentTimeMillis</i>();</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">switch</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MICROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// The following simulates a microseconds resolution </span><br />
<span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;"> // by advancing a static counter every time</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// a client calls the createClock method, simulating a tick.</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> us = current * </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">ONE_THOUSAND</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">if</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (us > </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> = us;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> } </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">else</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> { </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;"> </span><br />
<span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;"> // the time i got from the system is equals or less </span><br />
<span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;"> // (hope not - clock going backwards)</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// One more "microsecond"</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> us = ++</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> us;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MILLISECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">SECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current / 1000;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> };</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}</span></div>
<br /></div>
</div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[2]</span></b></div>
<br />
<div class="wp_syntax">
<div class="code">
<div class="MsoNormal">
<b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">enum</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <span style="background-attachment: scroll; background-color: silver; background-image: none; background-position: 0% 0%; background-repeat: repeat repeat;">TimestampResolutionPartiallySy<wbr></wbr>nchronized</span> {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">SECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MILLISECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MICROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;">/**</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> * The last time value issued. Used to try to prevent duplicates.</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: #3f5fbf; font-family: 'Courier New'; font-size: 10pt;"> */</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">static</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">final</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> AtomicLong </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> = </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">new</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> AtomicLong(Long.</span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MIN_VALUE</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">);</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> createTimestamp() {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current = System.<i>currentTimeMillis</i>();</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">switch</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MICROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// The following <u>simmulates</u> a <u>microsec</u> resolution </span><br />
<span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;"> // by advancing a static counter every time</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// a client calls the createClock method, simulating a tick.</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> us = current * 1000;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">if</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (us > </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.longValue()) {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.set(us);</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> } </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">else</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> { </span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// the time i got from the system is equals or less </span><br />
<span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;"> // (hope not - clock going backwards)</span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: #3f7f5f; font-family: 'Courier New'; font-size: 10pt;">// One more "microsecond"</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> us = </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">lastTime</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.incrementAndGet();</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> us;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MILLISECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">SECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current / 1000;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> };</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}</span></div>
<br /></div>
</div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[3]</span></b></div>
<br />
<div class="wp_syntax">
<div class="code">
<br />
<div class="MsoNormal">
<b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">enum</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> TimestampResolutionSimpleMicro {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">SECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MILLISECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MICROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">private</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">static</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">final</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">ONE_THOUSAND</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> = 1000L;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">public</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <span style="background-attachment: scroll; background-color: silver; background-image: none; background-position: 0% 0%; background-repeat: repeat repeat;">createTimestamp</span>() {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">long</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current = System.<i>currentTimeMillis</i>();</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">switch</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">this</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MICROSECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current * </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">ONE_THOUSAND</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">MILLISECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">case</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: #0000c0; font-family: 'Courier New'; font-size: 10pt;">SECONDS</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">:</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current / 1000;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> };</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: #7f0055; font-family: 'Courier New'; font-size: 10pt;">return</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> current;</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }</span><span style="font-family: 'Courier New'; font-size: 10pt;"></span></div>
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}</span></div>
</div>Anonymoushttp://www.blogger.com/profile/02865743639141548921noreply@blogger.com10