Posts
Mongo - Custom pessimistic locking mechanism
Problem: Having one thread updating a document at a time.
Solution: Lock manager:
<![CDATA[ /** * MongoDB document locking manager * (custom solution) */ @Component public class MongoLockManager { private WriteConcern WRITE_CONCERN = WriteConcern.MAJORITY; private int TIMEOUT = 2; private TimeUnit TIMEOUT_TIME_UNIT = TimeUnit.SECONDS; @Autowired private MongoClient mongoClient; @Value(“${spring.application.name}”) private String applicationName; private static final Logger logger = LoggerFactory.getLogger(MongoLockManager.class); /** * Inserts a document id in the product full details locking management collection * @param document the document containing the id to getLock */ public void insert(Document document) { Lock lock = new Lock(document.
Posts
Logstash - logstash.runner, An unexpected error occurred! does not exist, and I failed trying to create it
Problem: [FATAL][logstash.runnerĀ ] An unexpected error occurred! {:error=>#” does not exist, and I failed trying to create it
Solution: chmod -R 755
or,
chmod -R 755 /..
Posts
spring @async causing BeanCurrentlyInCreationException
Problem: Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘‘: Bean with name ‘’ has been injected into other beans [] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using ‘getBeanNamesOfType’ with the ‘allowEagerInit’ flag turned off, for example.
Posts
Linux - Grep, escape back slash characters
Problem: Execute ‘grep’ in order to match with: \“123456789\“
Solution: grep ‘\\\“123456789\\\”’
Posts
Hibernate - Exception "node to traverse cannot be null"
Problem: Hibernate exception “java.lang.IllegalArgumentException: node to traverse cannot be null”
Query query = session.createQuery(“delete ” +
”(…) “ +
“where map_material.id > map_material_1.id “ +
” and map_material.map_key = map_material_1.map_key “ +
”(…) “
Solution: Make sure to use hibernate “createSQLQuery” method
Query query = session.createSQLQuery(“delete ” +
”(…) “ +
“where map_material.id > map_material_1.id “ +
“and map_material.map_key = map_material_1.map_key “ +
”(…) “
Posts
Java - Transform string list into list
Problem: Transform a list of strings into a single string. One solution is to iterate over the list and append its contents. Remember that StringBuilder’s append is much faster than Strings concatenation.
Solution: A better solution is relying on Java StringJoiner
<![CDATA[ String.join(“, “, list); ]]>
SyntaxHighlighter.highlight();
, or with Java 8
<![CDATA[ String joinedFirstNames = list.stream() .map(String::toString) .collect(Collectors.joining(“, “)); ]]>
SyntaxHighlighter.highlight();