Skip to main content

Posts

Showing posts from January 18, 2019

MongoDB - Basic Commands

Greetings! These are the basic MongoDB commands we use in our day-today work. Adding as a reference to myself :) Create database use DATABASE_NAME $ use my_database Show databases $ show dbs Connect to database use DATABASE_NAME $ use my_database Drop database db.dropDatabase() Create Collection DB.COLLECTION_NAME.(OPTIONS) $ db.products.({ name: "Fruit Juice" }) Show collections $ show collections Drop collection db.COLLECTION_NAME.drop() $ db.products.drop() Insert document db.COLLECTION_NAME.insert(DOCUMENT) $ db.products.insert({ item_name: "Frui Juice", item_description: "sdfsdklf", price: "100" }) Read document db.COLLECTION_NAME.find() db.COLLECTION_NAME.find().pretty() $ db.products.find().pretty() $ db.products.find({ item_name: "Fruit Juice" }).pretty() Like statement - we have to use regex $ db.products.find( { item_name: { $regex: /789$/ } } ) AND $ db.COLLECTION_NAME.f...

Java Concurrency - Executor Framework

Greetings! What is the basic abstraction for creating threads in Java? Is it new Thread(new Runnable()) ? NO. It is Executors! Decoupling is a good programming practice and it is better to separate thread creation from the application. Java's way of encapsulating these functions are known as executors. ( Executors ) Executor Interfaces Executor - simple interface used to submit new tasks ExecutorService - sub interface of Executor which supports life cycle management of both of the tasks and Executor itself. ScheduledExecutorService - sub interface of ExcecutorService which supports task scheduling. ExecutorService This has more features than Executor interface. Mainly it support thread pooling, return the result via Callable, shutting down the service. execute(Runnable) submit(Runnable) submit(Callable) shutdown() This has following implementations in java.util.concurrent package. ThreadPoolExecutor ScheduledThreadPoolExecutor Creating a ExecutorServic...