Help coderanch get a
new server
by contributing to the fundraiser

Georgios Chatziefstratiou

Ranch Hand
+ Follow
since May 26, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
3
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Georgios Chatziefstratiou

Aritz Maeztu wrote:Spring is complaining about not having any MailSender to inject. How are you injecting it in your controller for your first case? The behaviour specified below is fully expected, if you remove the @Autowire dependency, Spring won't try to inject the instance, so the method will fail with a NullPointer when trying to send an email.


yes you are rigth but if i add @Autowire i will get couldn't create bean. I have the error above to see. What else i can do?
8 years ago
Hello. I have this method on my Controller for send email

XML config


This works fine and the email is send

The problem occurs when i create a service class and pass everything there.

The service Class



and i change my Controller like this


Then i cannot run the application because of this error



after some Hours i have removed @Autowire from the Service Class and i have try it again .Application loads correclty not like before but i have nullpointer Exception


I use Spring 3.2.3
and my pom.xml


Is this a problem of SimpleMailMessage mail ?
Why with Autowire does not workk if i move everything on My service Class.
I have also read spring docs and other but with no luck.
Any Help
thanks
8 years ago

Tushar Goel wrote:may be you have to use order by and limit together..

like:


yes something like that but the last 10 added ??
8 years ago
Hi to all

iam not sure if this goes here

does anyone know how can i print the last 10 query result i have made on my db inside a form in spring framework.How do i implement it ?
Should i create a table and store them and then recall them or in a file ?

is there other way any ideas . What is the best practice.

More clear is that i have a main screen and i want to have the last 10 query and their result in the screen
""
should show the last 10 queries and their results on the main screen as reminder
"""

thanks
8 years ago

Karthik Shiraly wrote:

the mongo writes are not real writes they are when the update failed


Ah, I see now. Sorry for the misunderstanding.

If what you want to do is something like this (in pseudo code):


then one way is to implement it using a fixed thread pool, a bounded queue, and a RejectedExecutionHandler. Basically, it uses the thread pool's feature
of rejecting tasks under certain conditions (such as bounded queue size) and then doing alternate processing for rejected tasks in the rejection handler.


Since I don't know your full application, I can't say if you need to retain all that 100ms polling of
thread pool active count, pool size, map lookup, etc.



thanks i will try it and come back i also have something new.
Create a trad pool for every subscriber and use it .

i will try them both and come back.

Karthik Shiraly wrote:I read your first post in detail even before my first reply. You have described what you think is a problem, implemented what you think is a solution, and are now asking a correction for that solution.
But you have not explained why you think it's a problem in the first place.
The closest statement is "I don't want it waiting", but you have not explained why not?

What really is the difference between
1) submitting task to unbounded queue executor and allow it to execute it at some point in future, without you having to code any additional logic
and
2) avoid submitting task now, instead hold it somewhere else (presumably in your own queue implementation) and then execute those rejected tasks at some point in future?

I'm asking these questions because from your code it looks like the "long running tasks" are mongodb writes, which usually not be long at all because mongodb is designed for fast writes.
Even if all threads in pool are busy at some instant, if all they are doing is writing to mongodb, they will finish within few millisecs or seconds.
Your statement "eventually threadpool will be with all threads in waiting" gives the impression that they will wait for ever, but that's not true at all. That's why I called it "temporary exhaustion".

I've used threadpools but have never seen any reason to implement logic that uses core pool checks or stack trace information. From the details so far, I feel you are on the wrong track with this code.



Hi again the mongo writes are not real writes they are when the update failed( this is my idea save to mongo use nothing else and when everything is ok the retrieve the failed update) due a reason so they go to mongo for a later update.

you mean with Future ?

Karthik Shiraly wrote:
1) submitting task to unbounded queue executor and allow it to execute it at some point in future, without you having to code any additional logic
and


can you explain what you mean

Karthik Shiraly wrote:
2) avoid submitting task now, instead hold it somewhere else (presumably in your own queue implementation) and then execute those rejected tasks at some point in future?




I have also seen that Smart Thread pool Code project
Have you read the first post? There i explain why.Eventually threadpool will be with all threads in waiting i am trying to avoid that.Because of (merely because of temporary threadpool exhaustion) that is the task i have.

Or to say it better how can i avoid temporary thread pool exhaustion when using spring ThreadPoolTaskExecutor or just java.
The idea is to make choose if i have less threads than i need if i have equal threads than i need
So i made a thread to fail if i have less because i dont want to have it waiting .How can i do it in the code i have create.
I need to know that the current thread has a subscriber and who is the subscriber so that i compare it.
Any help?

thanks giorgo

Karthik Shiraly wrote:

Georgios Chatziefstratiou wrote:how can i make the new thread notice that this subscriber is busy and fail the task for later send it to db to store it for later update.


Look into ThreadPoolExecutor if you aren't doing so already.

If you really want to fail and retry a task when threadpool is occupied, create the executor with a RejectedExecutionHandler (see the javadoc's "Rejected Tasks" section).

Probably a better option is not to fail any task but let it wait and get executed eventually. Use an unbounded queue for that (see the javadoc's "Queueing" section).


thanks for your reply i have create this code can you give some help.
I want to fail so that i can send it to the db to run later when the running thread is not running anymore.



Karthik Shiraly wrote:

Georgios Chatziefstratiou wrote:how can i make the new thread notice that this subscriber is busy and fail the task for later send it to db to store it for later update.


Look into ThreadPoolExecutor if you aren't doing so already.

If you really want to fail and retry a task when threadpool is occupied, create the executor with a RejectedExecutionHandler (see the javadoc's "Rejected Tasks" section).

Probably a better option is not to fail any task but let it wait and get executed eventually. Use an unbounded queue for that (see the javadoc's "Queueing" section).




is already made like this unbounded queue and if a task takes too long i am out of threads beacuse they are waitng for the one to finish.
thats why i have to change it i also thought to remove the queue but i need it.


thanks
Hi all ,

i have code that i count the current threads running on a sping project that is updating some subscribers.

The time between these updates is enough for a thread to finish the task that this thread has.Say i have subscriber 1 subscriber 2 subscriber 3
If a thread for example 1 goes to task(subscriber 1 ) 1 and stays blocked because of long running task and the other tasks are finished(subscriber 2 subscriber 3 ) , when a new update comes one thread is still running and the thread pool size is minus one thread. Example 5 threadpoolsize and then 4 threadpoolsize ,Because 1 thread is running.
The update will use a new thread and then second thread will have to wait for the first to finish the 1 task(subscriber 1 ) so that it can start and the other tasks are finished(subscriber 2 subscriber 3 ) .
Then the new update will come and start the new update and still a new thread will start to do the task and this have to wait until the first finishes and the second thread finishes, o i have minus 3 threads from the threadpoolsize.
So then I have 3 thread in waiting to do something. If this happens eventualy I ' ill be running out of threads if I have a thread pool of 5 threads.

and my question is how can i make the new thread notice that this subscriber is busy and fail the task for later send it to db to store it for later update.
I have seen semaphores and locks. Is there any other way or something else ?
I actually want to create a Thread Controller.

thanks

Georgios Chatziefstratiou wrote:

Georgios Chatziefstratiou wrote:Hi all
i have a mongo db and i have some performance issues takes too long to return results , what i need is just some help on the steps i have to follow to solve this.I am new to mongo but not new in databases.
What i thought think is to do something with indexes then map reduce or something simular .


any help suggestions.I forget to tell i use Hibernate.


thanks



So i have done a little research and come to that i have to change the index

i have the default index on mongo db and it's like this


correct me if i am wrong

so i was trying to find out how to create my new index and here is what i have so far.





I am not sure about 0 Zeros ?if i have to add the like that but iam not sure about all !

any help Bartender or someone ?



for what i am consider is that on the document maybe i have to declare all other leaves until the final.

For example on the index that i have done above the target is to have faster query when i search from a date to other date.

So the target is the dateinfo i am trying to make the index help my query to get faster dateinfo.

I am not sure if this is ok also what about 0 sometimes is a document and sometimes array.


thanks



I have the solution about the index .
Unfortunately this is not the problem.


What else can i do to slve this kind of problem query takes to long to give back results.

any ideas ? Is this forum dead?

8 years ago

Georgios Chatziefstratiou wrote:Hi all
i have a mongo db and i have some performance issues takes too long to return results , what i need is just some help on the steps i have to follow to solve this.I am new to mongo but not new in databases.
What i thought think is to do something with indexes then map reduce or something simular .


any help suggestions.I forget to tell i use Hibernate.


thanks



So i have done a little research and come to that i have to change the index

i have the default index on mongo db and it's like this


correct me if i am wrong

so i was trying to find out how to create my new index and here is what i have so far.





I am not sure about 0 Zeros ?if i have to add the like that but iam not sure about all !

any help Bartender or someone ?



for what i am consider is that on the document maybe i have to declare all other leaves until the final.

For example on the index that i have done above the target is to have faster query when i search from a date to other date.

So the target is the dateinfo i am trying to make the index help my query to get faster dateinfo.

I am not sure if this is ok also what about 0 sometimes is a document and sometimes array.


thanks

8 years ago
Hi all
i have a mongo db and i have some performance issues takes too long to return results , what i need is just some help on the steps i have to follow to solve this.I am new to mongo but not new in databases.
What i thought think is to do something with indexes then map reduce or something simular .


any help suggestions.I forget to tell i use Hibernate.


thanks
8 years ago

Junilu Lacar wrote:Georgios,

It's understandable that you probably cannot reveal the details of the method in a public forum such as this. You have indicated via PM that the method is huge. This is definitely a code smell. Huge methods often violate the SRP (Single Responsibility Principle) and that makes them more difficult to test. I don't know how much time and effort you can devote to refactoring the method but that is certainly one of the things I would look very seriously into doing if I were in your position. At the very least, I would be looking to apply the Compose Method refactoring.

Good luck.



thanks
8 years ago

Junilu Lacar wrote:A few "smells" right off the bat:

1. Having to create dummy objects, by which I'm assuming you mean mock objects.
2. The @Transactional annotation
3. The exceptions being thrown

Even though I refer to them as "smells," that doesn't necessarily make them bad things; they could be perfectly reasonable design choices. I consider these as "smells" because they probably raise the level of difficulty in testing the method and need to be looked at more closely with a design- and test-centric focus. My inclination would be to see if there was something that could be done to eliminate or mitigate the difficulties that these aspects of the design impose on testability. Without knowing more about the internal implementation of this method, however, it's hard for me to say more.



1 yes mock objects
2 @transactional annotation explain please
3 the exceptions beeing throw explain please



8 years ago
Hi all ,
i am new to testing so i need some advise on how to implement a test that i have.


thats the code i have of the method i need to test


from what i have read is that i have to create some dummys then have this

I am using eclipse and Spring with junit and Mockito.So what i have done is to create the 2 Dummys i need in my method then i supposed i have to create dummys for all the method code ?
is this aproach correct?

any advice on how to create the test

thanks



8 years ago