Almas Abdrazak
44 questions
1
votes
1
answer
76
views
Improve speed of insertion of big amount of data
I have a rest service that take xml with 400_000 records, each record contain the following fields: code,type,price.
In DB (MySql )I have table named PriceData with 2_000_000 rows. The purpose of this rest is: select all PriceDatas from DB according to code,type from XML, replace price of each Price...
1
votes
1
answer
623
views
Spring Mvc with async support vs Spring WebFlux
As i know(add if i miss smth) when we use Spring MVC application we have a pool of threads from our server(Tomcat...) when request is coming one of our thread from pool handle this request, sometimes it's a bad because if task take a long time our thread will be busy all this time, to avoid this beh...
1
votes
1
answer
211
views
Vertx add handler to Spring data API
In vertx if we want to execute jdbc operation that will not block main loop we use the following code,
client.getConnection(res -> {
if (res.succeeded()) {
SQLConnection connection = res.result();
connection.query('SELECT * FROM some_table', res2 -> {
if (res2.succeeded()) {
ResultSet rs = res2.resu...
1
votes
1
answer
168
views
How thread per connection use thread pool
I'm using Spring Boot and embedded Tomcat(8) and in app.prop file we have two options:
server.tomcat.max-connections = 1000
server.tomcat.max-threads= 20
From tomcat docs i have read that first option is the max number of connections that server can support and second option is the max number of th...
1
votes
1
answer
814
views
Reactor pattern how it works with threads
I study to learn Vert.x framework, but i don't understand how it work and what is Reactor pattern, i read this article https://dzone.com/articles/understanding-reactor-pattern-thread-based-and-eve and noticed that apart from standard design (one request one thread) Reactor pattern use event-drive...
1
votes
1
answer
58
views
Can't inject by qualifier
I have custom annotation named Retry with following Bean Post Processor:
@Component
public final class RetryBPP implements BeanPostProcessor {
private final Map map = new HashMap(40);
@Override
public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansExcept...
1
votes
0
answer
61
views
Handle APPLICATION_OCTET_STREAM using javax.ws.rs.client.WebTarget
I have a service which return APPLICATION_OCTET_STREAM file using this code:
@GET
public Response download(@BeanParam MovieUrl movieUrl) {
log.info('Request {} is handled',movieUrl);
final StreamingOutput fileStream = this.downloaderService.videoAsStream(movieUrl);
log.info('ok');
return Response.ok...
1
votes
1
answer
36
views
Add external properties file packaging war Spring Boot
I have .properties file with secured information such as database password ,username and so on, this file locate outside of src/resources folder.
Is it possible to add this file to war file on packaging step
Like:
mvn clean package -DAddResource=/home/user/secured.properties
1
votes
1
answer
95
views
Find biggest prices among huge amount of CSV files
I have 100 CSV files with following content
name,price
book,12.4
bread,54.23
Each file show content in sorted by price order
I need to find 10 most expensive products through all these files.This is my code:
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
impo...
1
votes
0
answer
39
views
Hibernate n+1 in native query (Spring Data)
I have three tables in Postgres
create table pool(
id PK
);
create table coin(
id PK
);
create table pools_coins(
id PK,
pool_id references to pool,
coin_id references to coin
);
Mapping is made only in Pools class
public class Pool extends Identifiable {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTab...
1
votes
1
answer
37
views
How to deploy WildFly locally?
I have war file with my Spring Boot project(REST API). I run this WAR in WildFly locally (http://localhost:8080).
Is it any way to send request from another device that use the same wifi as PC where this WAR is deployed? For example I need to send request from my mobile phone.
1
votes
1
answer
106
views
RPC pattern problems
I have read about RPC pattern from official docs, but examples are really simple. The client sends a message with reply_to and correlation_id properties, the server gets a message from the queue and resends it to the client binding the same correlation_id.
My questions are:
1) What if the server is...
1
votes
2
answer
431
views
Log http request body , if exception has occured
I have been developing rest api service using spring boot.
This is my rest controller
@RequestMapping(value = 'owner/login', method = RequestMethod.POST, produces = 'application/json;charset=UTF-8')
@ResponseBody
public ResponseEntity login(@RequestBody Owner owner) throws TimeoutException, SocketTi...
1
votes
1
answer
289
views
Static class to get connections from connection pool
I want to understand the concepts of connection pool.For example I have the following xml file in META-INF with my DB settings
To use connection pool I use the folliwng class
public class DataBaseConnection {
private static DataSource dataSource;
static {
try {
InitialContext initContext = new Init...
1
votes
1
answer
623
views
How to secure rest api using permissions
I'm developing rest api service using spring boot, to check permission I use token as - Save key value to memcache in login request, key it's token(string) with length 50 and value it's your id. To have access to any rest request my rest controller get this token as get parameter(the same logic with...
1
votes
3
answer
79
views
What is the best way to check for unique (SQL)
I have a simple MVC application in Java with db (Postgres) and table named users with the following columns:
name,email,age,birthday
One of the function: to register, the user should provide name and email. Both Fields must be unique in table (unique name and unique email)
To validate user input i u...
1
votes
1
answer
0
views
Jenkins run maven project through script instead of Maven Goal
I have the following pre build script in Jenkins:
#!/bin/sh set +e
kill $(lsof -t -i:8081)
mvn -f /var/lib/jenkins/workspace/project clean package
java -jar /var/lib/jenkins/workspace/project/target/site-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
My Maven Goal is empty,
when I run Build I have...
1
votes
1
answer
0
views
Jenkins fail to deploy war to Tomcat container second time
I want to deploy war file to tomcat 8 using Jenkins ,
And it deployed successfully , but when I press Build Now second time it show my the following error
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.223 s
[INFO] Finished a...
4
votes
1
answer
39
views
Wrong bytes from UTF-16 encoding
I have a character '😭' Unicode value is U+1F62D binary equivalent is 11111011000101101 . Now I want to convert this character to byte array . My steps
1) As binary representation is bigger than 2 bytes I use 4 bytes
XXXXXXXX XXXXXXX1 11110110 00101101
2) Now I replace all 'X' with '0'
00000000 00...
1
votes
1
answer
196
views
Convert java string with odd length to hex byte array
I need to convert string to hexademical byte array,my code is:
public static byte[] stringToHex(final String buf)
{
return DatatypeConverter.parseHexBinary(buf);
}
According to java doc to convert string to Hex DatatypeConverteruse the following implementation
public byte[] parseHexBinary(String s)...
1
votes
1
answer
1.2k
views
JPA native query insert returning id
I use the following code
EntityManager em.createNativeQuery('insert into users (name,surname) values (\'Test\',\'Test\') returning id').executeUpdate();
executeUpdate method return me 1 if insertion was success, but how can i get id of new user using the query above(my db is Postgres);
1
votes
1
answer
537
views
Vertx http server use only one instance of worker thread
I have a simple http vertx based server with the following code:
public class JdbcVertx extends AbstractVerticle{
private static int cnt;
@Override
public void start() throws Exception {
this.vertx.createHttpServer()
.requestHandler(request -> {
JdbcVertx.cnt++;
System.out.println('Request '...
1
votes
1
answer
37
views
Consumer which call method with object state [duplicate]
This question already has an answer here:
Is Java “pass-by-reference” or “pass-by-value”?
78 answers
I have a class
public final class GGGGG {
private final String str;
public GGGGG(final String str) {
this.str = str;
}
public void showElement(final String test){
System.out.println(this.st...
2
votes
1
answer
323
views
Vertx, how multithreading works
In Vertx official docs I read the following paragraph
If a result can be provided immediately, it will be returned immediately, otherwise you will usually provide a handler to receive events some time later.
Because none of the Vert.x APIs block threads that means you can use Vert.x to handle a lot...
1
votes
3
answer
334
views
Fork Join pool understanding
I have met a new class from java.util.concurrent package named ForkJoinPool
As i understand it works using the following scenario:
Divide the big task into subtasks(fork) and when each task is completed, gather all subtask(join), then merge it.
Fork join pool has a constructor public ForkJoinPool(in...
3
votes
3
answer
783
views
How to handle exception in DeferredResult in Spring Boot?
I have a rest method:
@RequestMapping(value = 'wash/washHistory', method = RequestMethod.GET, produces = 'application/json;charset=UTF-8')
@ResponseBody
public DeferredResult getWashHistory(@RequestParam(value = 'sid', required = true, defaultValue = '') String sid,
HttpServletResponse response, Htt...
2
votes
1
answer
57
views
Java UTF-16 String always use 4 bytes instead of 2 bytes
I have a simple test
@Test
public void utf16SizeTest() throws Exception {
final String test = 'п';
// 'п' = U+043F according to unicode table
// 43F to binary = 0100 0011 1111 (length is 11)
// ADD '0' so length should be = 16
// 0000 0100 0011 1111
// 00000100(2) 00111111(2)
// 4(10) 63(10)
f...
4
votes
1
answer
1.9k
views
Understanding the Tomcat Connection Pool settings
I want to know if my understanding of the Tomcat Connection pool lifecycle is correct.
For example, I have the following settings:
When my application is deployed it has 5 connections(initial size), when all these connections are busy tomcat create and add to pool a new connection(6), this new conn...
1
votes
1
answer
4.9k
views
Spring boot connection pool understanding
In Spring boot application.properties file we have the following options:
server.tomcat.max-threads = 100
server.tomcat.max-connections = 100
spring.datasource.tomcat.max-active = 100
spring.datasource.tomcat.max-idle = 30
This is my repository class
public interface UserRepository extends JpaRepos...
2
votes
1
answer
113
views
Postgresql postgis ST_DWithin always return true
I need to calculate if one point is not more distant than a given radius from another point. I used the function ST_DWithin, in google maps I get lanLot using 'what is here' section of two points. First: (43.2137617, 76.8598076) and second (43.220109 76.865100). The distance between them is 1.25km....
2
votes
1
answer
534
views
Crud Repository, date comparison
I have the following sql query:
select * from wash_history w where w.wash_id in
(select wash.id from wash where wash.car_wash_id = 17)
and w.time between '2017-07-13' and '2017-07-22'
And I want to create this query inside interface that extends CrudRepository. The method is
Page findWashHistoryByT...
2
votes
1
answer
51
views
Simple Cache mechanizm using decorators
I have a simple interface
public interface Text {
String asText() throws IOException;
}
And one implementation
public final class TextFromFile implements Text{
private final String path;
public TextFromFile(final String pth) {
this.path = pth;
}
@Override
public String asText() throws IOException...
1
votes
1
answer
808
views
Add new method to existing class
I know about anonymous class.We can use it to override class methods.This is an example:
public class User {
private final String name;
public User(final String name){
this.name=name;
}
public void sayHello(){
System.out.println('Hello : '+name);
}
public static void main(String[] args) {
User s =...
1
votes
1
answer
78
views
Connection pool based web server with async support vs Event Loop based web server
I'm learning about Vertx and it's ecosysteme, firstly i learned about Event loop, and the concept is really nice to me.
But since Servlet 3.1 we can use async support in JAVA based servers.
I'm using Spring and it's new class named deferredresult which can take thread from tomcat, give execution o...
2
votes
2
answer
74
views
How to rewrite it using stream api
I don't know all capabilities of Stream API.
My task is: I have a list of strings with urls and I have another list of my custom objects with two methods
String videoFromUrl(String url);
boolean support(String url);
I should to choose an url from first list which will be supported by one instance o...
2
votes
2
answer
33
views
Executor service shutdownNow , how it works
According to doc for method shutdownNow (ExecutorService)
There are no guarantees beyond best-effort attempts to stop
processing actively executing tasks. For example, typical
implementations will cancel via {@link Thread#interrupt}, so any
task that fails to respond to interrupts may never termina...
2
votes
1
answer
25
views
Can't access static resource using thymeleaf in specific end points
I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE)
This is project structure
As you can see I have html pages (test,test-exchange)
I have one controller to access these two pages:
test.html and test-exchange.html pages are absolutely the same
Here I have tagManager.js in t...
3
votes
2
answer
378
views
Vertx JDBC how it works under the hood
I have been using Vertx for 3 month, but now I wonder how non blocking Vertx JDBC works,for example
private void selectEndedMatches(){
this.jdbcClient.getConnection(conn->{
if(conn.failed()){
log.error('Can't get Vertx connection',conn.cause());
} else{
final SQLConnection connection = conn.result()...
2
votes
0
answer
62
views
Size of the class in Java
I have read this article http://btoddb-java-sizing.blogspot.com/
Author explain how to calculate Objects size in Java. For example:
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
public final class Perfomance {
static int number;
static int anotherNumber;
public static void main(String[]...
2
votes
1
answer
2.6k
views
NoClassDefFoundError: org/hibernate/boot/MetadataBuilder
I want to add PostGIS to my Spring Boot project, so I added the following dependencies:
4.0.0
com.gmoika
GmoikaApi
0.0.1-SNAPSHOT
war
GmoikaApi
GMoika project
org.springframework.boot
spring-boot-starter-parent
1.5.3.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-data-jpa
org.s...