Questions tagged [notify]

705 questions
187
votes
6 answers

A simple scenario using wait() and notify() in java

Can I get a complete simple scenario i.e. tutorial that suggest how this should be used, specifically with a Queue?
Olaseni
  • 7,250
  • 15
  • 41
  • 64
168
votes
11 answers

Java executors: how to be notified, without blocking, when a task completes?

Say I have a queue full of tasks which I need to submit to an executor service. I want them processed one at a time. The simplest way I can think of is to: Take a task from the queue Submit it to the executor Call .get on the returned Future and…
Shahbaz
  • 9,743
  • 18
  • 51
  • 71
54
votes
9 answers

Why are wait() and notify() declared in Java's Object class?

Why are the wait() and notify() methods declared in the Object class, rather than the Thread class?
Bhupi
  • 2,668
  • 5
  • 30
  • 48
51
votes
11 answers

Concept behind putting wait(),notify() methods in Object class

I am just having hard time to understand concept behind putting wait() in Object class. For this questions sake consider if wait() and notifyAll() are in Thread class. class Reader extends Thread { Calculator c; public Reader(Calculator…
Sunny
  • 1,604
  • 4
  • 22
  • 30
50
votes
10 answers

How can the wait() and notify() methods be called on Objects that are not threads?

How can the wait() and notify() methods be called on Objects that are not Threads? That doesn't really make sense, does it? Surely, it must make sense, however, because the two methods are available for all Java objects. Can someone provide an…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
41
votes
4 answers

Why does notifyAll() raise IllegalMonitorStateException when synchronized on Integer?

Why does this test program result in a java.lang.IllegalMonitorStateException? public class test { static Integer foo = new Integer(1); public static void main(String[] args) { synchronized(foo) { foo++; …
jjvainio
  • 561
  • 1
  • 5
  • 7
38
votes
6 answers

ClassCastException with ListView when executing notifyDataSetChanged

I have added a view to the header of listVivew, View TopSearch = (View) View.inflate(this, R.layout.search, null); lv.addHeaderView(TopSearch, null, false); And everything is fine until I try to execute (when data changes)…
bobetko
  • 4,666
  • 13
  • 56
  • 81
38
votes
7 answers

How to differentiate when wait(long timeout) exit for notify or timeout?

Having this wait declaration: public final native void wait(long timeout) throws InterruptedException; It could exit by InterruptedException, or by timeout, or because Notify/NotifyAll method was called in another thread, Exception is easy to catch…
Hernán Eche
  • 5,446
  • 11
  • 44
  • 71
23
votes
4 answers

Java Delay/Wait

How do I delay a while loop to 1 second intervals without slowing down the entire code / computer it's running on to the one second delay (just the one little loop).
Gray Adams
  • 3,147
  • 8
  • 26
  • 37
23
votes
5 answers

MySQL listen notify equivalent

Is there an equivalent of PostgresQL's notify and listen in MySQL? Basically, I need to listen to triggers in my Java application server.
smk
  • 3,901
  • 3
  • 23
  • 36
23
votes
13 answers

Cron with notify-send

I need to show a notification from a cron job. My crontab is something like: $ crontab -l # m h dom mon dow command * * * * * Display=:0.0 /usr/bin/notify-send Hey "How are you" I checked /var/log/syslog and the command is actually…
Ravi
  • 1,194
  • 2
  • 12
  • 24
22
votes
6 answers

Difference between Synchronized block with wait/notify and without them?

If I just use synchronized, not the wait/notify methods, will it still be thread-safe? What's the difference?
Alan
  • 497
  • 1
  • 3
  • 9
22
votes
8 answers

Java: How can a thread wait on multiple objects?

A thread can use Object.wait() to block until another thread calls notify() or notifyAll() on that object. But what if a thread wants to wait until one of multiple objects is signaled? For example, my thread must wait until either a) bytes become…
Tony the Pony
  • 37,471
  • 63
  • 170
  • 273
21
votes
4 answers

Fire trigger on update of columnA or ColumnB or ColumnC

I have the code to fire a trigger only on an update of a single specific column. The trigger is used to fire a function that will raise a postgres "notify" event, which I am listening for and will need to test and validate the newly input details.…
Martin
  • 807
  • 1
  • 9
  • 17
21
votes
3 answers

Android: After creating a new notification, the older one is replaced

I want to create a notification without canceling/deleting previous notifications from my app. Here is my code for creating a notification: private void notification(Context context, String title, String content) { NotificationCompat.Builder…
M.Veli
  • 429
  • 1
  • 5
  • 15
1
2 3
46 47