Common data structures used in java Garbage Collection techniques [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have come across the following question multiple times:
What data structures are used in garbage collection?
I haven't found many resources about the data structures used in GC algorithms.
Edit: I understand that the question seems too broad since there are
different kinds of garbage collection techniques. We could go with the
commonly used garbage collection algorithms, like the ones found in
most popular JVMs.

Your question is rather like asking "how does an operating system work?" There are many different algorithms for GC and they use different internal data structures depending on how the algorithm works.
Many algorithms use a root set as a starting point. This is a list of all the objects directly accessible from your application threads. It is created by scanning the thread stacks, registers, static variables, etc. The GC will typically process the root set to follow links to other objects (that are therefore accessible) and build a graph of all accessible objects.
There are other data structures like card tables but these are not used in all algorithms.
You might want to pick a particular GC algorithm and study that.

Related

General considerations when trying to determine what type of Java collection to use? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I understand that this question is very vague, but I'm trying to figure out a thought process to find out which collection is better to use when it comes to managing data.
I guess I'm just wondering if there is anything that screams "USE THIS ONE!", such as:
Big Data sets, lots of insertion and searching for a specific value: Best Collection Type
Big Data sets, sorting and data manipulation: Best Collection Type
Big Data sets, sorted by last add: Best Collection Type
Big Data sets, delete or move an item after x about of time: Best Collection Type
etc...
Little research
Assuming you are asking for decision-support, rather than for an opinionated "best-practice", I did a little research to find guidelines, comparisons, or even decision-charts.
Articles explaining the benefits and usage of collections
Here you find each of the major Java Collections explained:
Java Collections Cheat Sheet.
Here you find a list of questions to ask in order to choose the right one, as well as best-practice for using collections and their methods:
18 Java Collections and Generics Best Practices
Articles containing flow-charts for collection decision
I also found some decision flow-charts at similar question Rule of thumb for choosing an implementation of a Java Collection?, e.g. originally from Sergiy Kovalchuk's Blog:
Or viewed from different perspectives in LogicBic's tutorial Java - Collection Interfaces and Implementations
Maybe some SO-members would like to share their most applied Collections, with practical use-cases or experience from the professional field.

How to fit large table in memory? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a Java Map<String, List<String>>.
Is there a way to improve this to make it use less memory without having too much impact on performance?
Three ideas:
An encoded byte array could provide a less memory-intensive representation than a string, especially if the string data actually uses an 8 bit (or less) character set.
A list of strings could be represented as a single string with a distinguished string separator character between the list components.
String data is often compressible.
Depending on the nature of your data, these could easily give a 2 fold reduction in space for the lists.
The downside is that you may need to fully or partially reconstruct the original List<String> objects, which would be a performance hit.
You should also consider using a non-memory resident representation; e.g. a conventional database, a NOSQL database or an "object cache" framework. JVMs with really large heaps tend to lead to performance problems if you need to do a "full" garbage collection, or if there is competition for physical memory with other applications.
One would really need to know a lot more on your specific application to definitely recommend a specific solution, but as a wild guess, if it is a really, really large table (e.g hundreds of thousands or millions of records), I would suggest you consider using a database to store data and access via one of data layer access abstractions, such as DataSet.
Databases are already optimized to efficiently store, search and access data over an amortized data and time range, so without further info on your application, I would go with this option.

Concurrent queues performance [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Java 7 offers a wide range of different implementations of concurrent queues, namely:
java.util.concurrent.ArrayBlockingQueue<E>
java.util.concurrent.ConcurrentLinkedQueue<E>
java.util.concurrent.LinkedBlockingDeque<E>
java.util.concurrent.LinkedBlockingQueue<E>
Has anyone found any performance characteristics i.e. which one of those seem to be the fastest? I want to use one of the implementations for performance-critical section of my code.
There's no possible way to say which is the "fastest". That question doesn't make much sense. Fastest for what? You'd have to provide at least some amount of requirements. Garbage collection will have an effect. Caching behavior comes into play too and depends on data access patterns.
After determining that your performance requirements are not being met, and concretely identifying the container operations as a bottleneck via proper profiling and benchmarking, it is up to you to test and benchmark your own code in your own specific situations.
The concurrent collections generally exhibit the same high level performance characteristics as their vanilla counterparts.

What would be your interpertation of this requested queue implementation? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I had been reading two books on JAVA and while covering data structures, I started to do some online research with regards to "QUEUE" implementation. I have an extensive background in FLEX, however ACTIONSCRIPT isn't comparable to advance languages.
Lets say if I was on a job interview and asked to implement a Queue of Object, how should I pursue it as? I am not looking for code help here, I would like to what would you quick answer be? I have been to Java online docs and do understand there are 13 known implementing classes, and "LinkedList" is one of them.
Google search has return more results with "LinkedList" implementation code than any other.
My apologies if you find this question to be rubbish or pointless in anyway.
Oracle's Java online doc ref:
Do you know what the concept of a queue is and how it differs from a stack (closely related data structure)? If so, you should be able to think of multiple ways to implement it.
Which is best depends on the exact requirements of the task it's being used to address.
So the right response to that interview question is not to start coding but to ask them for more information about the requirements your implementation has to address. Performance? Memory size? Multitasking? Any limits on maximum queue depth, eg to guard against things like a DOS attack? What's being enqueued -- objects, primitives, other? Specific kinds thereof? Parameterized type? Are there any values which should be discarded (maybe null shouldn't be enqueued)?
Knowing the requirements, you should be able to judge which answer is appropriate. Starting coding without asking the requirements is immediately going to earn you a demerit.

Best data structure for large graph in cpu/memory bound environment [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm working on a academic project: writing a library for finding the shortest path on large, weighted, directed graphs.
Specifications are:
The example data set is a graph of 1500 vertices with an average of 5.68 edges per node. Specification may vary up to 20.000 nodes.
Moreover I'm working in a cpu / memory bound, environment: Android.
Edge weight is not trivial, nor costant. It depends on variable states of the graph.
We must work offline.
I face several difficulties:
I need an efficient way to store, retrive and update data of the graph. Should I use a SQLite object with queries from the Java classes, a large custom java object on the heap, or what? I think this is the most performance-critical aspect.
I need an efficient way to implement some kind of short path algorithm. Since all the weight are positive, should I apply the Dijikstra algorithm with an ArrayList as the container of the visited nodes?
Is this a good case to use the NDK? The task is CPU intensive, but it also make frequent access to the memory, so I don't think so, but I'm open to contribution.
Always remember that resources are scarce, ram is insufficient, disk is slow, cpu is precious (battery - wise).
Any advice is wellcome, cheers :)
For these many nodes I would suggest to aquire some Cloud-computing service and let the android app communicate with it.
How about Hadoop's MapReduce on Amazon's Cloud, there are many graph frameworks such as Mahout and it is really fast. And at least very scalable if there would be more nodes and edges.
linked list is best data structure for storing big sparse graphs.

Categories