DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Databases Topics

article thumbnail
A Deep Dive Into Couchbase N1QL Query Optimization
This comprehensive guide to N1QL queries covers the ins and outs of the query engine, teaching users about how to efficiently scan and join data.
December 16, 2016
by Keshav Murthy DZone Core CORE
· 16,851 Views · 9 Likes
article thumbnail
Designing Index for Query in Couchbase N1QL
It's important to remember that while designing an index, you should explore all possible index options.
December 16, 2016
by Sitaram Vemulapalli
· 9,027 Views · 10 Likes
article thumbnail
An Overview of Meta-Monitoring
Meta-monitoring is basically self-service for monitoring. There are several different requirements and methods that should be kept in mind when it comes to meta-monitoring.
December 15, 2016
by Thomas Kurian Theakanath
· 5,929 Views · 2 Likes
article thumbnail
Connecting to MongoDB in Scala
You can use Scala to connect to MongoDB with a handy driver. By tweaking some settings and adding a dependency, you can even use SSL to keep your connection safe.
December 15, 2016
by Neeraj Chinthireddy
· 16,635 Views · 1 Like
article thumbnail
JSON-B: A Java API for JSON Binding
When JSON-B and JSON-P are combined, all of the tools are put in place to process and work with the JSON data format in Java.
December 14, 2016
by Sam Sepassi
· 23,157 Views · 6 Likes
article thumbnail
Deploying Microservices: Spring Cloud vs. Kubernetes
When it comes to deploying microservices, which is better — Spring Cloud or Kubernetes? The answer is both, but they shine in different ways.
December 13, 2016
by Bilgin Ibryam
· 196,416 Views · 104 Likes
article thumbnail
How Small Should Microservices Be?
There are tons of different perspectives regarding the best size and granularity of microservices. Which perspective is best for your project?
December 12, 2016
by Grygoriy Gonchar
· 16,200 Views · 8 Likes
article thumbnail
About the Java 8 Stream API Bug
The Java Stream API wasn't working the way it was supposed to. There is a fix, but it's interesting to see what exactly went wrong.
December 12, 2016
by A N M Bazlur Rahman DZone Core CORE
· 16,860 Views · 17 Likes
article thumbnail
6 Frequently Asked Hadoop Interview Questions and Answers
Prepping for your upcoming interview? Unsure about what Hadoop knowledge to take with you? Here are 6 frequently asked Hadoop interview questions and the answers you should be giving.
December 11, 2016
by Arul Kumaran
· 34,333 Views · 15 Likes
article thumbnail
How to Use Asynchronous Timeouts in the Java Websocket API
In this post we take a look at how to deal with timeouts when using the Java WebSocket API. Read on to find out how and for some example code.
December 10, 2016
by Abhishek Gupta DZone Core CORE
· 12,309 Views · 4 Likes
article thumbnail
Mastering the Couchbase N1QL Shell: Connection Management and Security
Couchbase's cbq shell lets you write and run N1QL queries interactively. The shell also lets you securely interact with mixed nodes, among other handy tricks.
December 9, 2016
by Isha Kandaswamy
· 8,657 Views · 5 Likes
article thumbnail
Declarative Programming With Speedment 3.0
Learn more on the fundamentals of declarative programming in this in-depth article on the concept and see how Speedment implements declarative programming in practice.
December 9, 2016
by Dan Lawesson
· 11,176 Views · 8 Likes
article thumbnail
Create a REST API with Speedment and Spring
You can build a complete REST API with almost no manual coding using open-source Speedment and Spring.
December 9, 2016
by Emil Forslund
· 12,514 Views · 7 Likes
article thumbnail
ConcurrentHashMap isn't always enough
When Java developers come to a task of writing a a new class which should have a Map datastructure field, accessed simultaneously by several threads, they usually try to solve the synchronization issues invloved in such a scenario by simply making the map an instance of ConcurrentHashMap . public class Foo { private Map theMap = new ConcurrentHashMap<>(); // the rest of the class goes here... } In many cases it works fine just because the contract of ConcurrentHashMap takes care of the potential synchronization issues related to reading/writing to the map. But there are cases where it's not enough, and a developer gets race conditions which are hard to predict, and even harder to find/debug and fix. Let's have a look, at the next example: public class Foo { private Map theMap = new ConcurrentHashMap<>(); public Object getOrCreate(String key) { Object value = theMap.get(key); if (value == null) { value = new Object(); theMap.put(key, value); } return value; } } Here we have a "simple" getter ( getOrCreate(String key) ), which gets a key and returns the value assosiated with the given key in theMap . If there is no mapping for the key, the method creates a new value, inserts it into theMap and returns it. So far so good. But what happens when 2 (or more) threads call the getter with the same key when there is no mapping for the key in theMap? In such a case we might receive a race condition: Suppose thread t1 enters the function and comes to line 7. Its value is null . At this point thread t2 enters the function and also comes to line 7. Its value is also obviously null . Therefore from this point the two threads will enter the if statement and execute lines 8 and 9, thus creating two different new Objects. Upon returning from the getter each thread will get a different Object instance, violating programmer's wrong assumption that by using ConcurrentHashMap "everything is synchronized" and therefore two different threads should get the same value for the same key. To solve this issue we can synchronize the entire method, thus making it atomic: public class Foo { private Map theMap = new ConcurrentHashMap<>(); public synchronized Object getOrCreate(String key) { Object value = theMap.get(key); if (value == null) { value = new Object(); theMap.put(key, value); } return value; } } But this is a bit ugly, and uses Foo instace's monitor, which may affect performance if there are other methods in this class which are synchronized. Also a common rule of thumb is to try to eliminate using synchronized methods as much as possible. A much better approach should be using Java 8 Map's computeIfAbsent(K key, Function mappingFunction), which, in ConcurrentHashMap's implementation runs atomically: public class Foo { private Map theMap = new ConcurrentHashMap<>(); public Object getOrCreate(String key) { return theMap.computeIfAbsent(key, k -> new Object()); } } The atomicity of computeIfAbsent(..) assures that only one new Object will be created and put into theMap, and it'll be the exact same instance of Object that will be returned to all threads calling the getOrCreate function. Here, not only the code is correct, it's also cleaner and much shorter. The point of this example was to introduce a common pitfall of blindly relying on ConcurrentHashMap as a majical synchronzed datastructure which is threadsafe and therefore should solve all our concurrency issues regarding multiple threads working on a shared Map. ConcurrentHashMap is, indeed, threadsafe. But it only means that all read/write operations on such map are internally synchronized. And sometimes it's just not enough for our concurrent environment needs, and we have to use some special treatment which will guarantee atomic execution. A good practice will be to use one of the atomic methods implemented by ConcurrentHashMap, i.e: computeIfAbsent(..), putIfAbsent(..), etc.
December 8, 2016
by Dima Leah
· 48,740 Views · 12 Likes
article thumbnail
Top 5 Factors That Impact Your Software Performance
Knowing where your software is failing is essential to identifying the bottleneck. These five performance-impacting factors give you a good place to start.
December 7, 2016
by Thamwika Bergstrom
· 6,927 Views · 3 Likes
article thumbnail
How to Use Compare and Merge for SwaggerHub
Read on to find out how to keep API documentation shipping moving forward smoothly by using Compare and Merge for SwaggerHub.
December 7, 2016
by Keshav Vasudevan
· 8,077 Views · 4 Likes
article thumbnail
Apache Ignite With JPA: A Missing Element
Learn how to persist your entities with Apache Ignite and JPA. This tutorial will guide you through the setup of execution of that handy ability.
December 7, 2016
by Shamim Bhuiyan
· 15,234 Views · 14 Likes
article thumbnail
5 Signs That Your REST API Isn't RESTful
The author provides five criteria to help you make the distinction between an API that is RESTful based on the original meaning versus the colloquial meaning of REST.
December 6, 2016
by Robert Brautigam
· 37,760 Views · 43 Likes
article thumbnail
Java Holiday Calendar 2016 (Day 5): CRUD Operations
See how, with a handy open-source tool, you can alter your database entities, with standard CRUD operations, in Java.
December 5, 2016
by Per-Åke Minborg
· 9,250 Views · 6 Likes
article thumbnail
Keeping Submodules Up to Date in Git
When your project gets complicated, it makes sense to split it up into manageable chunks. Git supports this process using submodules.
December 5, 2016
by Tim Myerscough
· 9,497 Views · 2 Likes
  • Previous
  • ...
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×